Jump to content

[SOLVED] file download using php


maxelct

Recommended Posts

Dear All

 

I want users to be able to download a file. Its all working. When the user clicks the link the windows "File download" box pops up asking if the user wants to save/open etc.

 

Press save and the file will save. However, the estimated time left says "Not known 1.4Mb downloaded" etc.

 

How do I get it to show the estimated time left - i guess its something to do with fetching the actual file size from the server???

 

Here is the code that I have been using so far.

 

thanks in advance

 

Edward

 

$file_name= $_GET['name'];


header ("Content-Type:audio/mpeg");
header ("Content-Disposition: attachment; filename=$file_name");

readfile($file_name);

 

Link to comment
https://forums.phpfreaks.com/topic/69178-solved-file-download-using-php/
Share on other sites

You have to specify how many bytes follow, ie, "Content-Length:" (google it)

 

And put the  length of the file (in bytes), since the data is piped in a stream the browser has no idea when it will stop or how many bytes follow.

Archived

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

×
×
  • 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.