-
I have two requests:
1) I know a downloading script can be made to use php to get the file so that the user does not know the complete address of the file that they are downloading... can someone give me a link to this script?
2) Can you hide the location somehow that it is downloading from? ex. the windows explore download window says: Downloading ****.zip from Site.com. I want it to not show the Site.com or replace it with something else of my choice... is this possible? And how?
-
Assuming you have the location of the files in a table 'downloads', with fields 'id', 'location', and 'description', you need a script to list the files
PHP Code:
<?php
// file download_index.php
mysql_connect("host", "user", "password");
mysql_select_db("site_db")
$sql = "select id,description from downloads";
$result = mysql_query($sql);
while ( $row = mysql_fetch_array($result) ) {
echo "<a href=\"download_file.php?id=".$row['id']."\">".$row['description']."</a><br>";
}
?>
Then the actual download...
PHP Code:
<?php
// file download_file.php
if (!isset($id)) {
echo "No file selected";
die();
}
mysql_connect("host", "user", "password");
mysql_select_db("site_db")
$sql = "select id,location from downloads where id=$id";
$result = mysql_query($sql);
if (!$result) die();
$row = mysql_fetch_array($result);
//Do some fancy header stuff... (from php readfile() reference)
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-type: application/force-download" );
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) {
header( "Content-Disposition: filename=".basename($row['location']));
} else {
header( "Content-Disposition: attachment; filename=".basename($row['location']));
}
header( "Content-Description: File Transfert");
//readfile sends the file straight to output
@readfile($row['location']);
?>
Untested
You could probably get rid of all the database stuff if you protected the downloads directory with a .htaccess file. You could then send the location straight to the download_file.php script, letting users know where the file is, but they would be unable to access it directly.
-
Oh, and as for question 2, the browser has to get the file from somewhere, so it has to know either the domain name (www.domain.com) or the ip address (1.2.3.4). There might be a tricky way to stop IE from displaying it, but I doubt it.
-
Hi.
I haven't tried to completely hide the location of my downloadable files, but at least I can hide the exact path by using the following code
(this is BTW for jpeg-images)
PHP Code:
<?
$fp = fopen("../folder/subfolder/$_POST[file]","r");
$buff = fread($fp,1500000);
Header("Content-Type: image/jpg");
Header( "Content-Disposition: attachment; filename=$_POST[file]");
echo $buff;
?>
The referrer file sets the variable $file to whatever file the visitor wants to download. The download dialog box won't list the full path like mydomain.com/folder/subfolder/filename.jpg, but just mydomain.com
If you're rerouting from mydomain.com to download.com where you keep your downloadable files, its apparently possible to hide download.com and show mydomain.com instead, by using this code which was posted in another forum.