jessnoonyes Posted June 6, 2007 Share Posted June 6, 2007 I want to make a "download" button on my website that when pressed will download a file from my server. This is the code that I have: <?php $filename = "Book7_backup4.exe"; header("Content-Length: " . filesize($filename)); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=Book7_backup4'); readfile($filename); ?> But when I test it this is the message that I get: Warning: filesize() [function.filesize]: Stat failed for Book7_backup4.exe (errno=2 - No such file or directory) in /home/waldronf/public_html/maintenance-business/download.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /home/waldronf/public_html/maintenance-business/download.php:4) in /home/waldronf/public_html/maintenance-business/download.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /home/waldronf/public_html/maintenance-business/download.php:4) in /home/waldronf/public_html/maintenance-business/download.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at /home/waldronf/public_html/maintenance-business/download.php:4) in /home/waldronf/public_html/maintenance-business/download.php on line 6 Warning: readfile(Book7_backup4.exe) [function.readfile]: failed to open stream: No such file or directory in /home/waldronf/public_html/maintenance-business/download.php on line 8 What does that mean? Do you know how I can fix it? Thanks! Quote Link to comment Share on other sites More sharing options...
Lumio Posted June 6, 2007 Share Posted June 6, 2007 Is you application in the same directory as your script? Try header("Content-Length: " . filesize('./'.$filename)); Quote Link to comment Share on other sites More sharing options...
jessnoonyes Posted June 6, 2007 Author Share Posted June 6, 2007 the file I want downloaded? Yes. Quote Link to comment Share on other sites More sharing options...
Lumio Posted June 6, 2007 Share Posted June 6, 2007 Try my solution Quote Link to comment Share on other sites More sharing options...
jessnoonyes Posted June 6, 2007 Author Share Posted June 6, 2007 thanks. Tried that, got basically the same error Quote Link to comment Share on other sites More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 Try using an absolute path for $filename Quote Link to comment Share on other sites More sharing options...
per1os Posted June 6, 2007 Share Posted June 6, 2007 Warning: filesize() [function.filesize]: Stat failed for Book7_backup4.exe (errno=2 - No such file or directory) in /home/waldronf/public_html/maintenance-business/download.php on line 4 Are you sure the file is spelled that way, remember calling files is CaSeSeNSiTiVe. Also check that the file is in deed located at /home/waldronf/public_html/mainenance-business/ Quote Link to comment Share on other sites More sharing options...
jessnoonyes Posted June 6, 2007 Author Share Posted June 6, 2007 Now this is the error I get when I type an absolute path: Parse error: syntax error, unexpected '/' in /home/waldronf/public_html/maintenance-business/download.php on line 5 yeah I made sure I typed the file name in right, with the right capitalization. And that is where it's located. This is driving me nuts Quote Link to comment Share on other sites More sharing options...
jessnoonyes Posted June 6, 2007 Author Share Posted June 6, 2007 Is there a different php code I could use for the download instead? Quote Link to comment 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.