I'm storing files by reference, which means every file uploaded gets renamed to "temp_n", and stored in the database like ID, Name, Originalname, Mime
. So when I roll a download for any file, I go to the url getfile.php?i=$id
and grab the filed based off of the id. Here's my problem, it doesn't handle the files well, it will not show/force download the images, and it should force download any file there is. I'll do this to force download:
$url = "http".(!empty($_SERVER['HTTPS'])?"s":"")."://".$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']);
$dir = '/uploads/messaging/'.$room.'/';
$path = $url.$dir;
header("Content-Type: " . $mime);
readfile($path.$tname);
For the specified examples, $room
is 1 and is a valid folder, $path
is a valid path. I have tried storing the extension as well, and doing readfile($path.$tname.$ext)
where $ext
was .png, but it failed. I've messed around with headers, but max I got it to force it to download getfile.php
file instead of the file in question. The PHP code would contain this:
<br />
<b>Warning</b>: readfile(http://url/uploads/messaging/1/upload_IvRWZc) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
in <b>script/url</b> on line <b>32</b><br />
Where line 32 is the header in question, such as header("Content-Type: application/force-download");
or header('Content-Type: application/octet-stream');
.
The current examples shows a broken image link, it knows it's an image (based off of the mime) but it doesn't show it. What it should do is simply download the file requested. There is no .htaccess
in the folders and they are running 755
permission set.
PS. I'm not trying to trick users into downloading crap, I'm trying to make a secure file storage so nobody uploads funnyshell.php
to my server and has a blast with it.