I'm using the following code:
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$file_extension = strtolower(substr(strrchr($file,"."),1));
$mime_types=array();
...
...
$mime_types['mp3'] = 'audio/mpeg';
...
...
$mime_types['wma'] = 'audio/x-ms-wma';
$ext=strtolower(substr(strrchr($file,'.'),1));
$mime=$mime_types[$ext];
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Length: '.filesize($file)); // provide file size
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file); // push it out
$file contains both the directory and the filename, i.e.,
../Image/audio/My-Redeemer-LivesHS.mp3
The script opens the save as dialog box, with the proper file size, and allows me to save the file.
However: Some files work properly, others do not.
When loaded into Media Player, it says it cannot play the content. Real Player will handle some, but fail on others. Real Player couldn't handle the .wma file I tried, but handled ALL of the .mp3's; Media Player couldn't handle ANY of them.
The original files, if simply copied off the server into the directory via FTP, work fine. There's some sort of problem with the download script. It must be changing the internal structure of the files somehow.
I have provided a MYSQL database of the files available. The user chooses the file name, then clicks a button to download. This should pop up the 'save as/open' dialog box. Once the file has arrived, it should play... just as the original.
Since the original file isn't the problem, and the copy on the server side isn't the problem, ergo, the problem MUST be in the script. But... I'm stumped. I REALLY need this to work all the time, every time, with both audio and video file formats. I've tried several 'force download' scripts, but the end result is the same.
Anybody have any ideas? 😕