Jump to content

problem downloading files from a database


chishake

Recommended Posts

i have a new problem folks. this piece of code only downloads a pdf file. it doesnt work with other file types ( jpeg, jpg gif, doc etc.)

how can i have it working since my script has to be able to upload and download all types of files.

<?

// connect to the database

include "dbaseConnection.php";

 

 

$query = "SELECT * FROM images WHERE id =  1";

$result  = mysql_query($query) or die(mysql_error());

 

// define results into variables

$name=mysql_result($result,0,"name");

$size=mysql_result($result,0,"size");

$type=mysql_result($result,0,"type");

$content=mysql_result($result,0,"content");

 

// give our picture the proper headers...otherwise our page will be confused

header("Content-Disposition: attachment; filename=$name");

header("Content-length: $size");

header("Content-type: $type");

echo $content;

 

mysql_close();

?>

 

Sensei's suggested i should try adding quotes on the id.  that is not the problem because i dont get any error message. also it works if the file is a pdf file.  i get the download screen on all the types of files but when i click on open only the pdf file opens successfully. the others dont.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.