Header() to save mp3 moving slow...

I have a “save file” button for mp3 files on my site. I’ve never used the header() function before, so I’m not positive that I’m using it right here. It works perfectly on localhost. When I upload it to my host it works, but it takes forever for the save dialog to appear. You click the save file button and nothing happens until 20+ seconds later, then the dialog appears.

Here is the download.php

[php]

<?php header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: public'); header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="'.basename($_GET['f']).'"'); header('Content-Transfer-Encoding: binary'); readfile($_GET["f"]); ?>

[/php]

Ok, so it seems that the browser is downloading the complete file then showing me the save as dialog. When I select the place I want to save the mp3 the download bar pops up and its instantantly complete. Is there some way to ask the user where to save before the browser begins saving the file?

Instead of using this series of header calls you can just create the “Save File” button as a link to the file and the browser should do the rest. I am confused as to your intent with the header calls.

When I link directly to the MP3 file the browser opens it and plays it. It doesn’t ask the user for a save location unless you right click the link and find the save file option. Sure, the right click > save as works, and most people know how to use it, but I wanted this button for more convenience since this particular page is intended for saving MP3s to your hd rather than just listening to them.

Try this

Links

<a href="direct_download.php?file=fineline.mp3">Download the mp3</a>

download.php
[php]<?php
$file = $_GET[‘file’];
header (“Content-type: octet/stream”);
header (“Content-disposition: attachment; filename=”.$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service