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();

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.