Page 1 of 1

Hide URL to send file

Posted: Tue Aug 19, 2003 8:50 pm
by ganzina
Hi,

I'm using the following line to download a file:

header("Location: " . $downloadfile );

How can I hide the URL so the user doesn't know where the file is located on my website?

Thanks!

Posted: Tue Aug 19, 2003 10:40 pm
by tsg
Not sure if you can really hide it. If it is a file, such as a movie file, or somthing that can't be viewed via browser, maybe you could do something like:

download.php?file=4

and on the page use a variable like

if($file == 4) {
header("Location: " . $downloadfile );
}

Something like that. Just thinking out load. Maybe it will jar an idea...

Tim

Posted: Tue Aug 19, 2003 11:14 pm
by ganzina
I use a url with downloads.php?d=9
...

And then I do a redirect afterwards to go to another page, but the user can see the download link and also the path to the document. I've seen other websites do this and I'd love to know how they do it.

Thanks!

Posted: Wed Aug 20, 2003 3:56 am
by greenhorn666
You can pass the file to the client thru a php script:

Code: Select all

// Set the content type (we assume PDF here...)
header("Content-type: application/pdf");
// And set a name for the file
header("Content-disposition: attachment; filename=".basename($file));

// open the file
$fp = fopen($file);

// pass its content thru
fpassthru($fp);

// close the file
fclose($fp);
You can marry HTML output and join the file too, but not quite sure how, you'll have to look this one up (or lynx -dump -head http://www.whatever-site.com/does/it/how/you/want/url on unices)

Posted: Wed Aug 20, 2003 10:36 am
by ganzina
Thank you! It works perfectly.