akrytus Posted August 18, 2006 Share Posted August 18, 2006 This page is loaded multiple times as user clicks links to navigate through folders. When user clicks on a file, it is flagged. Then the page is reloaded to send the new headers to force the download but I get these errors. Can someone tell me why I am getting these errors?[quote]Warning: filesize() [function.filesize]: stat failed for /public_ftp/POS/Cash Registers/PCTOOL-VER-1_20.zip in /home/wtmalone/public_html/Dealer/dealer.php on line 9Warning: Cannot modify header information - headers already sent by (output started at /home/wtmalone/public_html/Dealer/dealer.php:9) in /home/wtmalone/public_html/Dealer/dealer.php on line 9Warning: Cannot modify header information - headers already sent by (output started at /home/wtmalone/public_html/Dealer/dealer.php:9) in /home/wtmalone/public_html/Dealer/dealer.php on line 10Warning: Cannot modify header information - headers already sent by (output started at /home/wtmalone/public_html/Dealer/dealer.php:9) in /home/wtmalone/public_html/Dealer/dealer.php on line 11Warning: Cannot modify header information - headers already sent by (output started at /home/wtmalone/public_html/Dealer/dealer.php:9) in /home/wtmalone/public_html/Dealer/dealer.php on line 12[/quote][color=red][font=Verdana]Here is the flag code:[/font][/color][code]function Flag_Download ($file,$dir){ $remote_file=$dir."/".$file; echo $remote_file; $_SESSION['download']=$remote_file; ?><meta http-equiv="Refresh" content="0; url=http://nocrs.net/Dealer/dealer.php"><?}[/code][color=red][font=Verdana]Here is the forced download code:[/font][/color][code] 1 <? session_start(); 2 3 // Download File if flagged 4 if(isset($_SESSION['download'])){ 5 $remote_file=$_SESSION['download']; 6 header("Pragma: public"); 7 header("Expires: 0"); 8 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 9 header("Content-length: ".filesize($remote_file));10 header("Content-Type: application/force-download");11 header("Content-Disposition: attachment; filename=".basename($remote_file));12 header("Content-Description: File Transfer");13 @readfile($remote_file);14 unset($_SESSION['download']);15 }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/ Share on other sites More sharing options...
lordphate Posted August 18, 2006 Share Posted August 18, 2006 You need to put the HEADER information ebfore ANYTHING else, needs to be at the top of the file...That's the problem :D Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76979 Share on other sites More sharing options...
akrytus Posted August 18, 2006 Author Share Posted August 18, 2006 [quote]You need to put the HEADER information ebfore ANYTHING else, needs to be at the top of the file...That's the problem [/quote]Before session_start? Becuase this is a secure page. What about the filesize error? How come lines 6,7,8 all went through ok? Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76980 Share on other sites More sharing options...
lordphate Posted August 18, 2006 Share Posted August 18, 2006 Try it after the sessionstart() if it doesn't work do it before hand Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76982 Share on other sites More sharing options...
akrytus Posted August 18, 2006 Author Share Posted August 18, 2006 Well that eliminated the errors, but nothing downloaded. Do you know why? Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76985 Share on other sites More sharing options...
Woolf Posted August 18, 2006 Share Posted August 18, 2006 [quote author=lordphate link=topic=104804.msg418231#msg418231 date=1155934111]You need to put the HEADER information ebfore ANYTHING else, needs to be at the top of the file...That's the problem :D[/quote]No, that's not necessarily true. You're true in the sense of it. However, header information needs to go before anything is echoed. You can define variables and all that before headers, you just can't echo anything before them.As for the error... have you tried checking the file with the FULL dir? e.g. /home/wtmalone/public_ftp/POS/Cash Registers/PCTOOL-VER-1_20.zip?So instead of your $dir as /public_ftp/POS/Cash Registers, use /home/wtmalone/public_ftp/POS/Cash RegistersAlso. It could be that you have spaces in the dir. If changing the dir as stated above does not work, try removing the spaces in 'Cash Registers' or replace it with an underscore. (e.g. /home/wtmalone/public_ftp/POS/Cash_Registers)And just an FYI: the reason it's giving you header errors is because the stat_failed error (Warning: filesize() [function.filesize]: stat failed for /public_ftp/POS/Cash Registers/PCTOOL-VER-1_20.zip in /home/wtmalone/public_html/Dealer/dealer.php on line 9) was echoed. Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76987 Share on other sites More sharing options...
akrytus Posted August 18, 2006 Author Share Posted August 18, 2006 OK, thanks wolf, let me check it out.Ohh you have to have session_start first, or I wont have my session variables that I need to even send the headers. Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76992 Share on other sites More sharing options...
lordphate Posted August 18, 2006 Share Posted August 18, 2006 That is true wolf, forgot about that...*shrugs* I tried...Sorry i wasn't as helpful as wolf, i'm still pretty new Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-76995 Share on other sites More sharing options...
Woolf Posted August 18, 2006 Share Posted August 18, 2006 [quote author=akrytus link=topic=104804.msg418244#msg418244 date=1155934951]OK, thanks wolf, let me check it out.Ohh you have to have session_start first, or I wont have my session variables that I need to even send the headers.[/quote]That is correct. It is best to always put session_start(); at the very top of the file (after the <? of course) before you define anything else. I do not believe you HAVE to, but it's just best to anyway. :) Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-77002 Share on other sites More sharing options...
akrytus Posted August 18, 2006 Author Share Posted August 18, 2006 Ok, all of you that helped me THANKS SO MUCH! Been working on this for over a week, getting a headache. Almost Done.One more thing. I can download any file but .txt files. The .txt files contain the html code of that page instead of what it should have. My guess is ascii over binary. Should I do an if statement on the extension to see if it is .txt and then some how use ascii instead, other wise use binary? How do you do that? Quote Link to comment https://forums.phpfreaks.com/topic/17987-header-errors/#findComment-77006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.