Jump to content

Download Page Not Working?


yobo

Recommended Posts

hey All

 

I am trying to create a download page I have managed to the upload page to add the file to the database etc..

 

however on my view.php, this page shows all the files that are in the database and allows the user to download a particular file to do this the view.php calls the download.php which processes the download.

 

however I am unable to pass the id along to the download.php, can anyone help?

 

this is the error on the view.php page

 

 

<a href="download.php?id=<?php '.$id.' ?>"><?php="$name";?></a> <br>

 

 

here is the source code for the view page

 

<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

//connect to database

$dbcon = @mysql_connect('localhost', 'root');
if(!dbcon) {

exit('<p> Unable to connect to database server</p>');
}

if(!@mysql_select_db('uploads')) {

exit('<p> Unable to select the database</p>');
}

$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php '.$id.' ?>"><?php="$name";?></a> <br>
<?php
}
}
?>

</body>
</html>

 

 

and this is the download.php page

 

<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database

//connect to database

$dbcon = @mysql_connect('localhost', 'root');
if(!dbcon) {

exit('<p> Unable to connect to database server</p>');
}

if(!@mysql_select_db('uploads')) {

exit('<p> Unable to select the database</p>');
}

$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, 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;


exit;
}

?>

 

thanks all sorry for the lenghtly post

 

Joe

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.