Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

GD refuses to work with local files

images php coding issues or problems here.

Moderators: macek, egami, gesf

GD refuses to work with local files

Postby samuel.simon » Wed Sep 28, 2005 3:35 am

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 http://www.tamariskfarm.com/construction/info.php)

test code:

Code: Select all
<?php

$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 = 'http://www.tamariskfarm.com/construction/resize/test.jpg';
//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 = 'http://us.i1.yimg.com/us.yimg.com/i/buzz/2005/09/0924cowboycheerleaderssmall.jpg';
//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);
    imagedestroy($image);

}

else

{
    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
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby Redcircle » Wed Sep 28, 2005 7:21 pm

when I try to view the image on your page I am getting The image “http://www.tamariskfarm.com/construction/resize/test.jpg” 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.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby samuel.simon » Wed Sep 28, 2005 10:24 pm

Sorry, I don't understand you. If I enter http://www.tamariskfarm.com/constructio ... e/test.jpg into a web broweser I get an image showing up. Are you saying that you get an error if you try this?
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby Alexej Kubarev » Fri Oct 07, 2005 12:39 pm

http://www.tamariskfarm.com/construction/resize/

there you will get an error: it will say that it cant show the image bla bla bla...
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby gesf » Fri Oct 07, 2005 6:06 pm

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 !?
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby samuel.simon » Fri Oct 07, 2005 11:57 pm

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 http://www.tamariskfarm.com/constructio ... /index.php

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.
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby samuel.simon » Sat Oct 08, 2005 12:00 am

The HTTP status is irrelevent. The code returns false on the if ($image = @imagecreatefromjpeg($filename))
line.
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby Alexej Kubarev » Sat Oct 08, 2005 1:53 am

remove @ and give us what erros you are getting..
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby samuel.simon » Sat Oct 08, 2005 2:41 am

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.
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby Alexej Kubarev » Sat Oct 08, 2005 2:48 am

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
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby samuel.simon » Sat Oct 08, 2005 3:01 am

If I change the line

if ($image = imagecreatefromjpeg($filename))

to

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.
samuel.simon
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Sep 28, 2005 3:14 am

Postby Alexej Kubarev » Sat Oct 08, 2005 3:16 am

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 http://www.php.net that you might want to check out..
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to PHP coding => Images

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.