Page 1 of 1

Temporary File Download System - Not downloading correctly

Posted: Sun Mar 04, 2012 2:56 pm
by TerryHarvey
Hi.

I'm having a little trouble. I followed the "Temporary File Download System" tutorial but I decided to leave out the expiry time. Here is my download page code:
<?php  
require ('core/inc/init.inc.php');

if(isset($_GET['file'])) {
	$file = (int)$_GET['file'];

	$sql = mysql_query("SELECT * FROM `files` WHERE `file_id` = {$file}");

	if (mysql_num_rows($sql) != 1) {
		echo 'That file does not exist';
	} else {
		$row = mysql_fetch_assoc($file);

		$path = "core/file/{$row['file_name']}";

		header('Content-Type: application/octetstream');
		header('Content-Type: application/octet-stream');
		header('Content-Description: File Transfer');
		header("Content-Disposition: attachment; filename=\"{$row['file_name']}\"");
		header('Content-Length: '.filesize($path));

		readfile($path);
	}
}
?>
However, when I try to download a file, I get the option to download the file "download.php" which contains the errors:
<br /><b>Warning</b>:  mysql_fetch_assoc() expects parameter 1 to be resource, integer given in <b>C:\xampp\htdocs\PHP\SQL\Download MOD\download.php</b> on line <b>12</b><br />
<br />
<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for core/file/ in <b>C:\xampp\htdocs\PHP\SQL\Download MOD\download.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>:  readfile(core/file/) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>C:\xampp\htdocs\PHP\SQL\Download MOD\download.php</b> on line <b>22</b><br />
What am I doing wrong?

Thanks.

Re: Temporary File Download System - Not downloading correct

Posted: Mon Mar 05, 2012 10:43 pm
by jacek
Add
echo mysql_error();
after the query causing the error, the MySQL server should then tell you what went wrong.

Re: Temporary File Download System - Not downloading correct

Posted: Tue Mar 06, 2012 12:20 pm
by TerryHarvey
I already tried that, it just displayed the same error as the one in the downloaded file.

Re: Temporary File Download System - Not downloading correct

Posted: Thu Mar 08, 2012 1:09 am
by jacek
TerryHarvey wrote:I already tried that, it just displayed the same error as the one in the downloaded file.
hmm, you must have put it in the wrong place :? You get the other errors because the query fails and returns false so the has to be an error :s

Can you post the code with the mysql_error() added ?