Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 21-07-2011, 06:24 PM   #1 (permalink)
Rising Sun!
 
buddyram's Avatar
 
Join Date: Feb 2011
Location: Bengalooor
Posts: 232
Cool PHP: File Downloading Query


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;
}
?>
__________________
“An expert is a man who tells you a simple thing in a confused way in such a fashion as to make you think the confusion is your own fault.” – William Castle

Last edited by buddyram; 21-07-2011 at 06:45 PM.
buddyram is online now   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:32 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2