GD refuses to work with local files



I had a set up that worked fine. Having returned from a period away I have some problems. GD won't load an image from the local server. It will open an image from another server and another server can open an image from the faulty server. My host claims to have made no changes while I was away.

Running PHP Version 4.3.6, GD Version 2.0.22 on SunOS ray 5.9 Generic_112233-11 sun4u. (full php info at

Test code:


$filename = 'test.jpg';
//Doesn't work
//test.jpg is in the same directory as the php file and both the directory and the files have permissions set to 0777

//$filename = '';
//Doesn't work when run from local host. When I take this php file and run from another server it works fine with this path.

//$filename = '';
//Works fine taking the image from a yahoo server, or any other server I have tried.

if ($image = @imagecreatefromjpeg($filename))
    header("HTTP/1.1 202 Accepted");
    header('Content-type: image/jpeg');
    imagejpeg($image, '', 100);



    echo '<h1>ERROR</h1>';
    echo 'filename : '.$filename.'<br>';
    echo 'fileowner : ' . fileowner($filename) . '<br>';
    echo 'fileperms : '  . substr(sprintf('%o', fileperms($filename)), -4) . '<br>';
    echo 'is_readable: ' . is_readable($filename) . '<br>';
    echo '<img src="'.$filename.'" alt="Image failed to load"><br>';



I wrote a php file that outputted the requested image file. When this was running on an external server it worked fine but when on the local server didn't work with GD (it showed the image perfectly when accessed directly).

An ideas? This has really confused me...

Samuel Simon
when I try to view the image on your page I am getting The image “” cannot be displayed, because it contains errors.

basically it loads the image but it does not stop trying to load it. Looks like that might be the problem.
Sorry, I don't understand you. If I enter into a web broweser I get an image showing up. Are you saying that you get an error if you try this?

there you will get an error: it will say that it cant show the image bla bla bla...
So... what about a 200 HTTP Status !? :)

202 says: "The request has been accepted for processing, but the processing has not been completed...".
So... your server will accept the request, but you'll always get some error message!

Am i right !?
Sorry, my original post didn't say where I had put the php code. The index file was another test of something else. I have now placed the code exactly as shown in my previous post at

I still don't havn't solved the problem but I have managed to work around it by making GD inport & export jpegs by string and using php for the file access.
The HTTP status is irrelevent. The code returns false on the if ($image = @imagecreatefromjpeg($filename))
I have removed the @ and get the following error:

Warning: imagecreatefromjpeg(): 'test.jpg' is not a valid JPEG file in /opt/Backups/Fulham/ray/www/opt/apache/htdocs/kitten/vhost/html/construction/resize/index.php on line 13

<img src="test.jpg" alt="Image failed to load"> shows the image.
what code for transformations are u using?
image create from jpeg creates a gd2 image and no a jpeg file..
there might be some problems with the jpeg file as well
If I change the line

if ($image = imagecreatefromjpeg($filename))


if ($image = imagecreatefromstring(file_get_contents($filename)))

it works just as I would expect it to.

This code is as simple as I could make it, apart from loading and outputting there is no transformation.
okey..well i think gd function most probably need the content of the file and not the filename.. if you wouldve had any transformation you wouldveneeded a gd2 image.. there are some examples at that you might want to check out..