Hide URL to send file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ganzina
Forum Newbie
Posts: 8
Joined: Mon Nov 04, 2002 4:18 pm
Location: California

Hide URL to send file

Post 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!
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post 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
ganzina
Forum Newbie
Posts: 8
Joined: Mon Nov 04, 2002 4:18 pm
Location: California

Post 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!
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post 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)
ganzina
Forum Newbie
Posts: 8
Joined: Mon Nov 04, 2002 4:18 pm
Location: California

Post by ganzina »

Thank you! It works perfectly.
Post Reply