Page 1 of 1

Force Download issue in Safari

Posted: Wed Mar 12, 2008 11:03 am
by astonishedman
I have a media application that I built in php. The client wanted a button for downloading the mp3 without having the visitor right click, etc. There is already handling for playing the audio online. This is strictly a download link.

I build the function to do this, addressing security issues by passing id variables to the force_download.php page and then that page pulls the files from the database based on the id.

The problem is that it words in every browser but Safari. In safari it will act like it is downloading and even places the file with the correct name on the desktop. But the file is 0kb and downloads in a second.

I have exhausted my search efforts and can't find a solution. I have tried different versions of my script below and none work. What am I missing for safari to be able to actually download the mp3? Any help will be appreciated.

Code: Select all

    header("Pragma: public");   // required
    header("Expires: 0");       // no cache
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    header("Content-Type: application/octet-stream;");
    header("Content-Disposition: attachment; filename=\"".basename($file_name)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ". filesize($file_name));   // provide file size
    set_time_limit(0);
    readfile($file_name) or die("File not found.");     // push it out
    exit();
 
$file_name is equal to the full url of the download mp3.

Re: Force Download issue in Safari

Posted: Wed Mar 12, 2008 11:06 am
by astonishedman
Oh, one more thing. For some reason it isn't getting the file size. On the download dialogs it says "unknown file size". So that may be a clue. But from all I know the line getting the file size should be correct. But obviously something isn't correct.

Thanks.
Keith

Force Download issue in Safari

Posted: Fri Mar 14, 2008 9:46 am
by astonishedman
Just following up on this issue. I haven't found any additional clues or solutions to this problem. Has anyone else run across this?