views:

287

answers:

1

I'm using the getimagesize() function in PHP and it keeps returning an error:

getimagesize(image.php?name=username&pic=picture) [function.getimagesize]: failed to open stream: No such file or directory

I'm not doing anything strange with it. The only problem I can imagine is that the path URL is another PHP script that returns a page with an image header, and there is an ampersand in that URL.

Here is my code:

$location = "image.php?name=username&pic=picture";
$size = getimagesize($location);
+2  A: 

You are expecting the php script to get executed? In that case you shouldn't try to open the file directly (it wont be executed) you should do something like

$location = "http://server.com/image.php?name=username&pic=picture";
$size = getimagesize($location);
The Disintegrator
Am I crazy? I just saw two other answers come and disappear while I was typing...
The Disintegrator
But then I get errors about direct URL something or other not being enabled on the server. I ran into that once with a different function and I know how to fix it, but I'd rather not as it makes things less secure.But the thing is, why shouldn't it execute from the relative directory path?
RobHardgood
I deleted my answer because I really wasn't sure about it.
karim79
jasonbar
I see... Is there any way around this besides using the full path, which is less secure and won't necessarily always be static?...
RobHardgood
It doesn't get executed because you aren't callyng the php interpreter. getimagesize does a direct file open operation (he doesn't know you are trying to open a script, he expects a image file. Thats why you need to add the protocol (http).The error is a php.ini configuration. You should change it to be able to use getimagesize in that way (it's something on the lines of allow_remote_file_open or something like that, I can't remember it right now)
The Disintegrator
you could user curl to call the php script. And write a temporary image file with the output...
The Disintegrator
Ah, interesting... Pardon my ignorance, but how would I do that with curl?...
RobHardgood
I had a thought, is there any way I could run the getimagesize function in my image.php script, and then pass the values through somehow?...
RobHardgood
the comment section doesn't allow me to paste too much text...But here's what you need http://ar.php.net/manual/en/curl.examples.php
The Disintegrator
getimagesize works with direct file open when you give it a local file, so in this case, there is no way.The way of doing this with getimagesize is specifying a full URL (or with the help of curl)
The Disintegrator