View Full Version : Hiding download link

03-14-2003, 11:51 PM
I've been to a few sites where when you download a file the file download dialogue comes up, but instead of saying the name of the file, it says redirect.php or download.php or whatever. But when you select save to disk it then shows you the tru name of the file so that you can browse and save it to disk. I tried header("location: file.exe"), but with that the filename is shown. Any ideas?

03-15-2003, 02:14 AM
I do that with mp3s; a file called download.php in the root directory:


$saveName = stripslashes($HTTP_GET_VARS["name"]);
$savePath = stripslashes($HTTP_GET_VARS["path"]);

header ("Content-Type: application/octet-stream");
header ("Content-Disposition: attachment; filename=$saveName");
header ("Content-Transfer-Encoding: binary");


And then you call it with URIs like this:

<a title="MP3 download" href="/download.php/?path=music/hifi/song.mp3&name=song.mp3">

You can improve that by passing the filesize as another parameter; I think there's a header for that as well, something like "File-Size" - that way, the download dialogue will tell you how big it is, and estimate the download time :)

03-15-2003, 05:19 AM
Works like a charm. Thanks.

Just a couple things I'd also like to ask. First off is there any way the user can tell where the file really is if I don't use a form, just the header part (doubt it but want to be sure)? Also, if I'm using this with a larger file will it require a lot of work on the servers part to parse the file?

03-15-2003, 05:31 AM

header("Content-Length: ".filesize($filename));

Pulled out of the post by the user "lists at darkcore dot net" on php.net - header (http://www.php.net/manual/en/function.header.php)

11-02-2003, 10:48 PM

I have a similar problem like this one.

I want to have a download link, but instead of filename (in that script you can download a file that you specify) I want to put a direct link(url) to the other site's filename.

I think that should be just a minor change in the script, but I'm new in php, so any help from you php masters is appreciate.

thanx in advance :thumbsup:

11-03-2003, 12:19 PM
Use a database as the mp3 thing is not safe at all...

use get id
then do a query and then use some download code for it to prompt to save the file, they wont see the download location except from www.xxx.xxx

11-03-2003, 12:57 PM
I need to know what to change in above code that would work with url not with filename.

I don't wanna use it for mp3's but for pdf/doc files, so hidding link like www.xxx.xxx is not my problem.
My problem is how to replace/change that line:

header ("Content-Disposition: attachment; filename=$saveName");

with something like this:

header ("Content-Disposition: attachment; URL =$saveName");

So once again; I have a download link, after I click it I want to get an option like "Save as". My link is basicly just a link to other site's link where is some pdf.

Could you please corect the above code for me? :rolleyes: