chishake Posted December 19, 2007 Share Posted December 19, 2007 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/ Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Try adding single quotes to the WHERE id = '1' Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/#findComment-418530 Share on other sites More sharing options...
~n[EO]n~ Posted December 19, 2007 Share Posted December 19, 2007 Add header("Content-type: image/jpg"); before header("Content-Disposition: attachment; filename=$name"); maybe.. Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/#findComment-418531 Share on other sites More sharing options...
chishake Posted December 19, 2007 Author Share Posted December 19, 2007 i have added the header("Content-type: image/jpg"); but it still doesnt work. i actually get the download screen with the file size and type. but when i click to open the file, it downloads but doesnt show. only pdf file opens Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/#findComment-418541 Share on other sites More sharing options...
~n[EO]n~ Posted December 19, 2007 Share Posted December 19, 2007 Try adding single quotes to the WHERE id = '1' Did you try Sensei style Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/#findComment-418547 Share on other sites More sharing options...
chishake Posted December 19, 2007 Author Share Posted December 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/82341-problem-downloading-files-from-a-database/#findComment-418553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.