php force MP3 'save as' dialog
i have implemented a working script from the interwebnethighway into my
site that forces a 'save as' dialog to pop up on clicking an mp3 link,
tho you do not get the estimated time remaining or progress bar showing
up, is there any way to make it show up, or is this simply because im
messing about with headers and leaving no proper info?
much apprectiated, thanks!
script used:
~~~~~~~~
(fileurl comes from previously in the script.....)
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off'); }
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: audio/x-mp3");
header("Content-Disposition: attachment;
filename=\"".basename($FileURL)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($FileURL));
readfile("$FileURL");
exit();
Re: php force MP3 'save as' dialog
| if(ini_get('zlib.output_compression')) {
| ini_set('zlib.output_compression', 'Off'); }
takes longer to check the 'if' condition than to just call
ini_set()...setting it 'off' has no effect when it is 'off' and, has the
correct effect when it is 'on'. further, iirc, if it is 'on', it comes to
the browser compressed but the browser uncompresses it once it is all
received. if the browser doesn't support compression, none of this matters
anyway.
| header("Pragma: public");
| header("Expires: 0");
| header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
| header("Cache-Control: private",false);
| header("Content-Type: audio/x-mp3");
| header("Content-Disposition: attachment;
| filename=\"".basename($FileURL)."\";" );
| header("Content-Transfer-Encoding: binary");
| header("Content-Length: ".filesize($FileURL));
these are the headers i usually use...although i have used force-download
before as well (sorry for the wrapping):
require_once 'site.cfg.php';
$fileData = '';
$fileName = $_REQUEST['fileName'];
$filePath = $site->uploadBaseDirectory;
if ($fileName != ''){ $fileData = [at] file_get_contents($filePath .
$fileName); }
header('pragma: public' );
header('expires: 0' );
header('cache-control: private', false );
header('cache-control: must-revalidate, post-check=0, pre-check=0' );
header('content-disposition: attachment; filename="' . $fileName . '"' );
header('content-size: ' . count($fileData) );
header('content-transfer-encoding: binary' );
header('content-type: application/octet-stream' );
echo $fileData;
Re: php force MP3 'save as' dialog
sorry, so looking throught seems quite similar to my version
does your version bring up the more standard "downloading" box (with a
progress bar and time remaining)
"Steve" <no.one [at] example.com> wrote in message
news:wNPth.33$eK3.29 [at] newsfe04.lga...
>| if(ini_get('zlib.output_compression')) {
> | ini_set('zlib.output_compression', 'Off'); }
>
> takes longer to check the 'if' condition than to just call
> ini_set()...setting it 'off' has no effect when it is 'off' and, has the
> correct effect when it is 'on'. further, iirc, if it is 'on', it comes to
> the browser compressed but the browser uncompresses it once it is all
> received. if the browser doesn't support compression, none of this matters
> anyway.
>
> | header("Pragma: public");
> | header("Expires: 0");
> | header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> | header("Cache-Control: private",false);
> | header("Content-Type: audio/x-mp3");
> | header("Content-Disposition: attachment;
> | filename=\"".basename($FileURL)."\";" );
> | header("Content-Transfer-Encoding: binary");
> | header("Content-Length: ".filesize($FileURL));
>
> these are the headers i usually use...although i have used force-download
> before as well (sorry for the wrapping):
>
> require_once 'site.cfg.php';
> $fileData = '';
> $fileName = $_REQUEST['fileName'];
> $filePath = $site->uploadBaseDirectory;
> if ($fileName != ''){ $fileData = [at] file_get_contents($filePath .
> $fileName); }
> header('pragma:
> );
> header('expires:
> );
> header('cache-control: private',
> );
> header('cache-control: must-revalidate, post-check=0,
> ck=0' );
> header('content-disposition: attachment; filename="' . $fileName .
> );
> header('content-size: ' .
> );
> header('content-transfer-encoding:
> );
> header('content-type:
> );
> echo $fileData;
>
>
>
Re: php force MP3 'save as' dialog
"Karl" <nospam> wrote in message
news:pv2dnasJXeO2SCrYnZ2dnUVZ8t-nnZ2d [at] bt.com...
| sorry, so looking throught seems quite similar to my version
|
| does your version bring up the more standard "downloading" box (with a
| progress bar and time remaining)
it depends on the broswer. however, the first window in ie is a 'open / save
as' dialog box. after 'open' has been clicked, or after you've 'save[d] as',
the progress bar and time remaining dialog is shown.
yes, our versions are strickingly similar, however the content type is
completely different. i use octet-stream vs. force-download since it seems
to do the trick among the majority of browsers...not just ie. it also allows
me to use that code in one script to deliver any kind of content to the
browser for opening/saving.
hth
Re: php force MP3 'save as' dialog
had to remove the script in the end, it was causing peoples computers to
download 1kb empty mp3s instead of the actual file!
how irritating.
"Steve" <no.one [at] example.com> wrote in message
news:kNQth.718$do5.380 [at] newsfe06.lga...
>
> "Karl" <nospam> wrote in message
> news:pv2dnasJXeO2SCrYnZ2dnUVZ8t-nnZ2d [at] bt.com...
> | sorry, so looking throught seems quite similar to my version
> |
> | does your version bring up the more standard "downloading" box (with a
> | progress bar and time remaining)
>
> it depends on the broswer. however, the first window in ie is a 'open /
> save
> as' dialog box. after 'open' has been clicked, or after you've 'save[d]
> as',
> the progress bar and time remaining dialog is shown.
>
> yes, our versions are strickingly similar, however the content type is
> completely different. i use octet-stream vs. force-download since it seems
> to do the trick among the majority of browsers...not just ie. it also
> allows
> me to use that code in one script to deliver any kind of content to the
> browser for opening/saving.
>
> hth
>
>
Re: php force MP3 'save as' dialog
post your script...i bet it's a path problem.
Re: php force MP3 'save as' dialog
it was working for some people tho (including me on IE7) so surely that path
isnt incorrect?
the path comes from a full length string from a mysql database
i've lost interest in it now anyway. People will just have to learn to use
"save target as..." unless anyone has a complete working script (progress
bar/time remaining while downloading included) such as the one on
djdownload.com
thanks for replying tho :)
"Steve" <no.one [at] example.com> wrote in message
news:lFswh.18$9X3.2 [at] newsfe02.lga...
> post your script...i bet it's a path problem.
>
>
Re: php force MP3 'save as' dialog
sorry i couldn't be more help.
best of luck.