OK, sorry for not being clear. Here's what I'm trying to achieve. Let's say my DocumentRoot is at
/data/webstuff/html
My downloads are at
/data/webstuff/html/downloads
So, if you know the name of a file in the "downloads" folder, you can just type this into your browser:
http://www.mydomain.com/download/file.zip
The problem with that is that it bypasses my security. What I want to be able to do is put my downloads here...
/data/downloads
...so that there's NO WAY you can get to the files with a URL. Problem is, I can't figure out how to provide access to those files via PHP.
Here's what I've tried. Maybe you can tell me what I'm doing wrong.
index.php calls the download script like so:
<a href="getfile.php?12">download12</a>
The number 12 is the key in the database. getfile.php looks like this:
<?php
$path = "/data/downloads";
mysql_connect('localhost', 'user', 'pass')
or die (mysql_errno() . ": " . mysql_error() . "<br>\n");
mysql_select_db('dbname')
or die (mysql_errno() . ": " . mysql_error() . "<br>\n");
$sql = "SELECT url FROM main WHERE id = $QUERY_STRING";
$result = mysql_query($sql)
or die (mysql_errno() . ": " . mysql_error() . "<br>\n");
$row = mysql_fetch_row($result);
$download = $path . $row[0];
header("Content-type: application/zip");
readfile($download);
?>
This doesn't work. What happens is that readfile tries to get...
getfile.php?12
...for some reason. I know that $download is being formed correctly, because when I comment out the last two lines and replace it with...
print $download;
...it shows me the correct value of...
/data/downloads/file.zip.
So, what am I doing wrong? I know I must be doing something dumb here, but I can't figure it out. And BTW, I've looked at many "anti-leech" scripts for the answer, but all the ones I've seen require you to have the downloads accessible via URL, and use other means to protect the content.