Why not use an absolute path instead of:
header('Content-Type: image/jpeg');
readfile('home/folder/my image.jpg');
like this:
// notice the absolute path prefix
if(!is_file($image_path = '/home/folder/my image.jpg')){
header('Content-Type: text/plain', 404);
echo 'Image file not found!';
}
// We got a file, keep going...
header('Content-Type: image/jpeg');
header('Content-Length: '.filesize($image_path));
readfile($image_path);
die; // done here
Or use the path relative to current directory of .php
script with __DIR__.'/path/to/image.jpg'
.