I am trying to read a thumbnail image using its file path.
$thumb = "/location/of/image";
$getInfo = getimagesize($thumb);
header('Content-type: ' . $getInfo['mime']);
readfile($thumb);
The result is an image error icon.
So far I have tried;
- checking if the file exists
var_dump(file_exists($thumb));
result :
bool(true)
-
check the getInfo to make sure it is an image:
var_dump($getInfo);
result:
array(7) {
[0]=>
int(100)
[1]=>
int(94)
[2]=>
int(2)
[3]=>
string(23) "width="100" height="94""
["bits"]=>
int(8)
["channels"]=>
int(3)
["mime"]=>
string(10) "image/jpeg"
}
which appears to be correct (size mime type etc.)
. using file_get_contents($thumb) instead of file_read (a complete reach, but I had run out of ideas).
I checked the file it is reading and I am able to download and view the image without problems, also if I call the file directly from my browser, the image displays fine. So it doesn't look like there
-
forced the file to download instead of display:
header("Content-Type: application/force-download");
The resultant file is not recognised by any of my image editors/views, or by a browser. A range of errors, from "incomplete" to "unrecognized format" result, even when I set the download file name explicitly to "thumb.jpg".
I am out of ideas! Has anyone go any other suggestions how I can debug this issue?
Thanks in advance for your suggestions :)