I tried increasing the memory_limit as was suggested in another question. Getting the sizes of images from other sites works fine both locally and remotely, but for this site, only locally. What might be going on?

probably because your trying it on a remote file, vs a local, your host may not allow this.From the manual "It can reference a local file or (configuration permitting) a remote file using one of the supported streams. "
–
DagonMar 20 '11 at 21:04

getting the size info works fine on all other sites I've tested both locally and remotely, just not this site specifically.
–
jelaMar 21 '11 at 15:56

trying the url you provided, it redirects, there's the issue, curl can follow redirects get the image and you can check its size locally.
–
DagonMar 21 '11 at 19:26

yes I actually just tried cURL following Anomie's suggestion, and it looks like you're right about forwarding being at least part of the problem. However I'm confused why getting the image size works fine on my local server even though the image link gets forwarded. Does this mean there is some way to make getimagesize() handle forwarding?
–
jelaMar 22 '11 at 0:34

2 Answers
2

It sounds like your shared hosting may have allow_url_fopen disabled. If you haven't already, you should configure error logging and make sure you're not disabling error reporting in your scripts. It's probably giving you an error message to indicate why it is failing.

allow_url_fopen is enabled on the remote server. adding error_reporting(E_ALL); to my script I get a result of Notice: getimagesize(): Read error! in /hsphere/local/home/url/get_image_size.php on line 4. The script works fine for all other images I have tested both locally and remotely, but none of the images off this site (remotely, locally they work fine).
–
jelaMar 21 '11 at 16:06

@jela: Oh, it's just one specific site you can't get the images from? It sounds like that one site may be blocking requests from your server. Can you download the image with wget or curl?
–
AnomieMar 21 '11 at 16:53

I can download from curl no problem, although I noticed I needed to use curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 ); to get the curl to work. I then noticed that visiting the link to the image images.jcrew.com/erez4/erez?src=images/eiec/39/39251/… forwards me to images.jcrew.com/erez4/cache/…, and if I replace the former link with the latter in my script, the image dimensions can be obtained from the remote server. Could this be related to the problem?
–
jelaMar 22 '11 at 0:20

@jela: I see two possibilities at the moment: either the script behind the first URL is checking your User-Agent (try ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)')?), or your shared host somehow has max_redirects set to 0 or 1 in the default stream context (can you find or make another image URL that redirects to test with?).
–
AnomieMar 22 '11 at 3:00

changing the user_agent didn't work. I created a redirecting image on the remote server itself, and the script on the remote server cannot get its image size, but the script on my local server can, so the problem is definitely the redirect. I tried changing max_redirect with $opts = array('http' => array( 'max_redirects' => 20 ) ); stream_context_get_default($opts); without success. I'm still a bit confused on how properly to change the max_redirect option on the default stream.
–
jelaMar 22 '11 at 13:59

allow_url_fopen is enabled. adding error_reporting(E_ALL); I get a result of Notice: getimagesize(): Read error! in /hsphere/local/home/url/get_image_size.php on line 4 when attempting to get image sizes off this site running the script on the remote server, but not when running the script on my local server. getting images from other sites works fine both locally and remotely for other all other sites I have tested.
–
jelaMar 21 '11 at 16:11