Jump to content

Download button


jessnoonyes

Recommended Posts

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!

Link to comment
Share on other sites

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/

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.