brucensal Posted December 8, 2007 Share Posted December 8, 2007 Hi, Can anyone shed some light on this code for me. I have managed to get a form to upload multiple images into 1 databse record per client. I am now trying to download the uploaed files so i can work with them. The code below works to a point i can view both files but when i click on the to download it only downloads to first file even though it does list the correct file names. If you could help me with this it would be greatly appreciated. <? if(isset($_GET['id'])) { // Details for webhost below://////////// //////////////////////////////////////// $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*****", $con); $id = $_GET['id']; $query = "SELECT name, type, size, content FROM ***** WHERE id = '$id'"; $query2 = "SELECT name2, type2 ,size2, content2 FROM ***** WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); $result2 = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); list($name2, $type2, $size2, $content2) = mysql_fetch_array($result2); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); echo $content; header("Content-Disposition: attachment; filename=$name2"); header("Content-length: $size2"); header("Content-type: $type2"); echo $content2; } ?> <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body,td,th { font-family: BankGothic Lt BT; font-size: 12px; } --> </style></head> <body> <? // Details for webhost below://////////// //////////////////////////////////////// $con = mysql_connect("localhost","******","*****l"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*******$con); $query = "SELECT COUNT(id) AS numrows FROM *****"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; $query = "SELECT id, name, name2 FROM *****"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "<br>"; echo "<br>"; echo "$numrows <b>Download(s)in our database</b>"; echo "<br>"; echo "<br>"; echo "Database is empty <br>"; } else { echo "<br>"; echo "<br>"; echo "$numrows <b>Download(s)in our database</b>"; echo "<br>"; echo "<br>"; while(list($id, $name, $name2) = mysql_fetch_array($result)) { ?> <a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br> <a href="download.php?id=<?=$id;?>"><?=$name2;?></a> <br> <? } } mysql_close($con); ?> </body> </html> EDITED BY WILDTEEN88: Please use code tags ( ) when posting code within a post. Thank you Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 8, 2007 Share Posted December 8, 2007 You cannot use the same header multiple times. Only one or the other will be received, usually the first. The others will be ignored. What you'll want to do is is perhaps get the files out the database then create an archive file (zip/rar etc) to store them in. Then you'd use 1 header for downloading the archive file. Quote Link to comment Share on other sites More sharing options...
brucensal Posted December 8, 2007 Author Share Posted December 8, 2007 Hi, Thanks for responding. Can u ponit me in the direction of where i can find some examples of how to do that. Much appreciated. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 9, 2007 Share Posted December 9, 2007 If you are using PHP5 then you could read this Zend article. Quote Link to comment 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.