PHP: File Downloading Query

buddyram

New Voyage
I am unable to download the file from the database which i had uploaded, instead it is downloading a txt file which describes the file information, with warning!

Could anyone trace this?

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

if(isset($_GET['id']))
{
  //if id is set then get the file with the id from database
  $mysql = mysql_connect('localhost','root','');
  mysql_select_db('upload',$mysql);
  $id = $_GET['id'];
  $query = "SELECT name, type, size, content FROM uploadtbl WHERE id = '$id'";
  $result = mysql_query($query, $mysql);
  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;
}
?>
 
Last edited:
Top Bottom