Posted by Hilarion on 07/01/05 12:45
> I'd like to let user download a file but I'd like to hide the url of the
> file.
> I'd like to write something like that:
>
> <a href="download_file.php?id=1123">download file</a>
>
> download_file.php get the file and give it to user.
> BUT...
> ... how can I write download_file.php?
> thank you in advance for your help,
<?php
// download_file.php
$file_locations = array(
1 => 'my/location/file1.zip',
2 => 'my/dislocation/file2.doc',
1123 => 'some/important/file.dbf'
);
Header( 'Location: http://my.server.com/' . $file_locations[ IntVal( $_GET[ 'id' ] ) ] );
?>
You could also read the file contents and return it to client
(giving correct headers first) but this way you'll block download
resuming etc. The main flaw of the solution above is that the
user can get the file location and then use it bypassing
download_file.php.
A good idea would be to get file locations from some database
(not PHP array) and to store somewhere information about
download performed (for download stats).
Hilarion
Navigation:
[Reply to this message]
|