williamh26 Posted October 23, 2014 Share Posted October 23, 2014 Hi Guys I trying to download files and I have this error message, hopelly you guys can help me please Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 14Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 15Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 16Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 17Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 18 This is the code I use to force the download <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path="core/files/{$row['$file_name']}"; header('Content-Type:application/octet-stream'); header('Content-Description:File Transfer'); header('Content-Transfer-Encoding:binary'); header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); header('Content-Length:'.filesize($path)); readfile($path); } } } ?> Thank you for your help..... Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/ Share on other sites More sharing options...
requinix Posted October 23, 2014 Share Posted October 23, 2014 output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6Whatever is there created output and you cannot use header() if there has been output. Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494538 Share on other sites More sharing options...
williamh26 Posted October 24, 2014 Author Share Posted October 24, 2014 Thank you.... fixed... but now this is the error I have C:\Users\folder1\AppData\Local\Temp\AADMn2IX.jpg.part could not be saved, because the source file could not be read.Try again later, or contact the server administrator. The image failed to saved and download it. thank you Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494567 Share on other sites More sharing options...
mac_gyver Posted October 24, 2014 Share Posted October 24, 2014 it would help if you provided some context for the last error message. what exactly were you doing when you got that error? Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494575 Share on other sites More sharing options...
williamh26 Posted October 24, 2014 Author Share Posted October 24, 2014 Ok, it was blank spaces on the login function... once I delete those spaces,, it works. thank you for the reply. <?php mysql_connect('xxxx','xxxx','xxxx'); mysql_select_db('xxxx'); ?> Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494642 Share on other sites More sharing options...
williamh26 Posted October 26, 2014 Author Share Posted October 26, 2014 When I am trying to download the file, it shows me this error..... can you guys give me a hint... thanks C:\Users\folder1\AppData\Local\Temp\AADMn2IX.jpg.part could not be saved, because the source file could not be read. Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494818 Share on other sites More sharing options...
requinix Posted October 27, 2014 Share Posted October 27, 2014 Does it happen every time you try to download a file? What browser? Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494874 Share on other sites More sharing options...
williamh26 Posted October 27, 2014 Author Share Posted October 27, 2014 yes it happens all the time.... in firefox and IE Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1494983 Share on other sites More sharing options...
williamh26 Posted October 28, 2014 Author Share Posted October 28, 2014 How I fix it!!! if anyone knows it... please. thanks Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495051 Share on other sites More sharing options...
Gaab Posted October 29, 2014 Share Posted October 29, 2014 <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path= file_get_contents('core/files/'.{$row['$file_name']}); header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); header('Content-type: application/force-download'); header('Content-Length:'.filesize($path)); header('Content-type: application/octetstream'); echo $path; } } } ?> Test this! Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495149 Share on other sites More sharing options...
requinix Posted October 29, 2014 Share Posted October 29, 2014 header('Content-Length:'.filesize($path));strlen instead of filesize. Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495158 Share on other sites More sharing options...
williamh26 Posted November 5, 2014 Author Share Posted November 5, 2014 it works but now it does not show the image Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495751 Share on other sites More sharing options...
requinix Posted November 5, 2014 Share Posted November 5, 2014 One more typo: $path= file_get_contents('core/files/'.{$row['$file_name']});Too many $s. Get rid of the unnecessary {}s while you're there. Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495763 Share on other sites More sharing options...
williamh26 Posted November 5, 2014 Author Share Posted November 5, 2014 thank you very much it works.... <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path= file_get_contents('core/files/'.$row['file_name']); header("Content-Disposition:attachment;filename=\"$row{['file_name']}\""); header('Content-type: application/force-download'); header('Content-Length:'.strlen($path)); header('Content-type: application/octetstream'); echo $path; } } } ?> I will continue with this project....thnak you Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495874 Share on other sites More sharing options...
requinix Posted November 6, 2014 Share Posted November 6, 2014 header("Content-Disposition:attachment;filename=\"$row{['file_name']}\"");The variable there is a bit off. The {}s should be around the whole thing, like header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); Link to comment https://forums.phpfreaks.com/topic/292021-temporary-download-files/#findComment-1495876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.