I have tried with your code and found no problem. After read your comment and try with your file thetexturemill.com/wp-content/uploads/2013/07/dell.png
I have this code working:
# my demo value in my local machine
$path = dirname(__FILE__) . "/demo";
$file_name = "Capture.PNG";
#$fn = realpath($path.'/'.$file_name);
$fn = "http://thetexturemill.com/wp-content/uploads/2013/07/dell.png";
//var_dump(readfile($fn));
$mm_type="application/octet-stream";
#$mm_type=mime_content_type($fn);
#echo $mm_type; die();
ob_get_flush();
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: " . $mm_type);
#header("Content-Length: " .(string)(filesize($fn)) );
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header("Content-Transfer-Encoding: binary
");
readfile($fn);
flush();
die();
What problems I found are:
- If you use an image from remote host, make sure you can get it (the
allow_url_fopen
INI option is ON
and the returned value from readfile
is greater than zero) and do not use filesize
as well as mime_content_type
functions.
- I don't know whether
thetexturemill.com
is your domain name or folder name. Supposed that it is a domain name, remember to add the protocal prefix (http://
as in example)
- Do not output anything before the
header
function calls or your downloaded file will not be open properly.
Ah, for local file, your original code work without errors on my machine.