Re: Displaying files from database

From: Date: Wed, 28 Mar 2007 17:59:26 +0000
Subject: Re: Displaying files from database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-251552@lists.php.net to get a copy of this message
On 3/28/07, Philip Thompson <prthomp@uark.edu> wrote:
Hi. 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. ~Philip
You 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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#251552) next »