Re: Displaying files from database
| From: | Philip Thompson | Date: | Wed, 28 Mar 2007 18:36:31 +0000 |
| Subject: | Re: Displaying files from database | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-251557@lists.php.net to get a copy of this message | ||
On Mar 28, 2007, at 12:59 PM, Tijnema ! wrote:
On 3/28/07, Philip Thompson <prthomp@uark.edu> wrote:Yup, that was it - I needed to add the decode... of course the obvious. It works! And yes, I prevent SQL injection and other stuff - that's just not shown here. Thanks for the advice! =D ~PhilipHi. I'm storing an uploaded file into a MySQL database. I want the file to then be downloaded and viewed. Uploading looks like: <snippet> if (is_uploaded_file($file) && $filename) { $handle = fopen ($file, 'r'); $resume["data"] = base64_encode (fread ($handle, filesize ($file))); fclose($handle); $resume["type"] = $_FILES['resume']['type']; $resume["size"] = $_FILES['resume']['size']; } </snippet> It loads into the database fine. If it's a word document, it merely spits out plain text. If it's a PDF, it says it can't open it. Downloading looks like: <snippet> $app = applications ($_GET["id"]); header ("Status: 200 OK"); header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header ("Content-Length: ".$app["size"][0]); header ("Content-Type: ".$app["type"][0]); header ("Content-Disposition: attachment; filename=Resume-".$app ["full"][0]); echo $app["resume"][0]; exit; </snippet> What am I doing wrong?!! =D Thanks in advance. ~PhilipYou base64_encode your file when reading, you should also base64_decode i think. so: echo base64_decode($app["resume"][0]); And you get $app from $_GET, and later use it as an array. I hope you did some database actions between :) Tijnema