Struggling with file download script in PHP
Posted: Sun May 23, 2010 4:36 pm
Hi everyone:
I've spent probably about an hour trying to fix this issue. My goal is to let people download a short WMV file. If I simply post a link, it automatically goes into Media Player and not the download screen. So I came up with the following script to have a download window pop up instead:
Everything works fine, except that when a download begins both IE and Firefox don't show a download progress bar, and instead say, "Estimated time left not known". I checked the file size and it is reported correctly. What am I doing wrong?
I've spent probably about an hour trying to fix this issue. My goal is to let people download a short WMV file. If I simply post a link, it automatically goes into Media Player and not the download screen. So I came up with the following script to have a download window pop up instead:
Code: Select all
//$fpath = Path of the file on the server
//$download_file_name = is the name of file, how it will appear for a user
$len = @filesize($fpath);
header("Content-Type: application/x-video-wmv");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
header("Content-disposition: attachment; filename=\"$download_file_name\"");
if(@readfile($fpath) === false)
ShowError("ERROR: Cannot output the file, please contact administrator...");