Jump to content

Archived

This topic is now archived and is closed to further replies.

akrytus

Header Errors

Recommended Posts

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 9

Warning: 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 9

Warning: 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 10

Warning: 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 11

Warning: 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]

Share this post


Link to post
Share on other sites
You need to put the HEADER information ebfore ANYTHING else, needs to be at the top of the file...That's the problem :D

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
[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 Registers

Also. 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
That is true wolf, forgot about that...*shrugs* I tried...Sorry i wasn't as helpful as wolf, i'm still pretty new

Share this post


Link to post
Share on other sites
[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. :)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.