Finglish
Finglish

Reputation: 9956

Why is my image not being displayed correct when loading it using readfile

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;

var_dump(file_exists($thumb));

result :

bool(true)

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 am out of ideas! Has anyone go any other suggestions how I can debug this issue?

Thanks in advance for your suggestions :)

Upvotes: 3

Views: 1682

Answers (1)

tliokos
tliokos

Reputation: 3636

You can try this:

$thumb = "/location/of/image";

$getInfo = getimagesize($thumb);

header('Content-type: ' . $getInfo['mime']);

ob_clean();

flush();

readfile($thumb);

Probably there is some white space before your opening php tag.

Upvotes: 5

Related Questions