Philip Thompson 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:

Assuming you actually have a good reason *why* you are storing uploaded files in your database, how has the table been set-up? What is the table type and the column you are storing this file in? Is PHP set to automatically magic quote the data on insert? If so, you're in for a world of pain, so disable it.

if (is_uploaded_file($file) && $filename) {
  $handle = fopen ($file, 'r');

You should always fopen with 'rb' for binary safe, system-portable handling.

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.

What are the size of these files? First of all, you need to base DECODE your data before sending to the client. Secondly, check if SQL is automatically escaping the data, which will cause you no end of trouble.

Third, if your files are larger than the maximum amount of memory a single PHP script can use on your server, your way of doing this will fail, because you are echoing out the data.

Actually storing the files as files, and then using passthru() to send them to the browser avoids this limitation. As it stands, if there is a 4MB file, each call to your script for it will use 4MB of memory minimum, so I hope you've got a dogs-bollocks server there, or a pitifully low traffic site ;)

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

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

Reply via email to