Re: Displaying files from database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/28/07, Philip Thompson <prthomp@xxxxxxxx> 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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux