Jump to content

Recommended Posts

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;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/135921-downloading-from-server-or-database/
Share on other sites

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

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.