I have a problem where when I run the PHP code offline, there are no errors
produced and the code runs as expected. However when I uploaded the same
script and run it, it says the headers have already been sent.
The script is for a "downloader " type script, where the user clicks on a
file link (to the PHP script) using $_GET to pass the selected files ID to
the script, and the information about the file is read out from a database,
also updating a field in the database on how many times a file has been
accessed, and then produces the browsers "save as" dialog box according to
which file type was accessed.
Below is the code, if anyone can help how to sort this problem out. I put
line numbers in to show where the errors occur, along with the error
report.
Thanks
Dariusz
// Connect (log on) to the database
$connection = @mysql_connect( "localhost" , "xxx", "xxx");
mysql_select_db ($DatabaseName) ;
// Display database entries
$sql = mysql_query("SE LECT * FROM $TableName WHERE f_id='$FileID'" );
$FileInfo = mysql_fetch_row ($sql); <-- Line 22
// Read from the array the files URL
$FileURL = 'http://'.$FileInfo[0];
// Read from the array the files name
$FileName = $FileInfo[1];
// Read file size from the database
// Problem using the built-in function to read file size of stated file
$FileSize = $FileInfo[2];
// Write code for number of accesses a file has had
$FileAccessed = $FileInfo[3];
$FileAccessed = $FileAccessed + 1;
$sql = ("UPDATE $TableName SET f_accessed=$Fil eAccessed WHERE
f_id='$FileID'" );
$result = @mysql_query($s ql, $connection);
$FileType = substr($FileID, 0, 3);
MYSQL_CLOSE();
//Screensavers
if ($FileType == 'scr')
{
// We'll be outputting a screensaver
header('Content-type: application/octet-stream'); <-- Line 46
// Filename
header("Content-Disposition: attachment; filename=$FileN ame;"); <-- Line48
header('Content-Transfer-Encoding: binary'); <-- Line 49
// Calculate file size
header('Content-Length: '.$FileSize); <-- Line 51
// The location of the file
readfile($FileU RL); <-- Line 53
}
Errors:
Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result
resource in /home/php/downloader.php on line 22
Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
46
Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
48
Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
49
Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
51
Warning: readfile(http://): failed to open stream: Success in
/home/php/downloader.php on line 53