mamavi Posted December 7, 2008 Share Posted December 7, 2008 hi everyone. i have a problem downloading files uploaded into mysql database. The code snippet i have displays the files as links, however when this is clicked. i get the forbidden message(error 404). i will like to know of a way to view files uploaded onto the apache server. Anyway, below is the code snippet for the download: ??? ??? <?php include "dbconn.php"; mysql_select_db("Library"); $query = "SELECT id, name FROM PastQuestions"; $result = mysql_query($query) or die("not selected"); if(mysql_num_rows($result) == 0) { echo "database empty<br/>"; } else{ while(list($id,$name) = mysql_fetch_array($result)) { ?> <a href=\"download.php?id <?php echo $id;?>\"><?php echo $id.".<nbsp><nbsp>".$name;?></a><br/> <?php } } ?> <?php if(isset($_GET['id'])) { include "dbconn.php"; mysql_select_db("Library") or die("Error selecting database"); $id = $_GET['id']; $query = "select name, type, size, content from PastQuestions where id = '$id'"; $result = mysql_query($query) or die ("Query failed"); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename = $name"); echo $content; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135921-downloading-from-server-or-database/ Share on other sites More sharing options...
corbin Posted December 7, 2008 Share Posted December 7, 2008 404 is not found. Are you sure you're going to the page correctly? Quote Link to comment https://forums.phpfreaks.com/topic/135921-downloading-from-server-or-database/#findComment-708779 Share on other sites More sharing options...
.josh Posted December 8, 2008 Share Posted December 8, 2008 My first guess is that you're missing the = in your href='...' <a href=\"download.php?id=<?php echo $id;?>\"><?php echo $id.".<nbsp><nbsp>".$name;?></a><br/> Also, you're going to have to wrap your code before the if(GET...) to only show if GET doesn't exist, otherwise you're going to get some header errors when that condition evaluates true... Quote Link to comment https://forums.phpfreaks.com/topic/135921-downloading-from-server-or-database/#findComment-709195 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.