PHP Force File Download Code - Error
i am using the following code
<?php
$rFile = $_GET['sfile'];
$rExt = $_GET['ext'];
header("Content-disposition: attachment; filename=".urlencode( $_GET['sfile'] ).".".$_GET['ext']);
header('Content-type: Image/jpeg');
readfile( "wallpapers/".$rFILE.$rRes.$rExt );
?>
i pass the variables and the files are being downloaded.. but the images are not being created ..
- i see a image file with image icon with correct name but theres no preview
- the images are not opened in any image viewer (all the images i use are JPEGs)
- all the downloaded images have same size 336 to 337 bytes... so i thought maybe transfer size is limited and so i use Similar SO Question开发者_StackOverflow but after that only the file size grew to 445bytes to 446bytes nothing more...
WHAT TO DO.. i need to provide direct links for image download...
I'll bet a beer that the 336 to 337 bytes contain a PHP error message that will tell you what the problem is.
Remove the JPEG content-type header to see the output.
at line 1 you're witing $rFile
, in line 5 it's $rFILE
- maybe thats the problem? if not, it's impossible to say without seeing the error-message.
I hope that you are doing some sanitizing of $_GET data or you'll have a lot bigger problems than image data not downloading correctly. That code is ripe for a directory traversal attack.
okay now i did this
$rFile = $_GET['sfile'];
$rExt = $_GET['ext'];
header("Content-disposition: attachment; filename=".urlencode( $_GET['sfile'] ).".".$_GET['ext']);
header('Content-type: Image/jpeg');
readfile( "wallpapers/".urlencode($rFile).".".$rExt );
now the files are being download with correct size.. but i still can't see the preview.. my image veiwers & editors say this
ACDsee blank screen
Windows Page & Fax Viewer no preview available
MS Paint path Paint Cannot Read This File This is not a valid bitmap file. Or its format is not supported
精彩评论