Jump to content

Getimagesize Function With Absolute Img Url?


son

Recommended Posts

I use the getimagesize function as

$path = "images/";$pic = $row['picture'];$size = getimagesize("$path$pic");

which works fine so far.Now my website structure goes a bit deeper and for files one level down I would like to use the same include files etc. The getimagesize funtion is in header include file and I tried to have an absolute path to image. As soon as I replace 'images/' with 'http://www.domain.co.uk/images/' the getimagesize funtion does not work. Is this normal?Son

Link to comment
Share on other sites

Yes, you can't get a file size over HTTP (without actually fetching the file), so getimagesize() won't work over a remote connection. You could temporarily download the file and then check :)

Link to comment
Share on other sites

Yes, you can't get a file size over HTTP (without actually fetching the file), so getimagesize() won't work over a remote connection. You could temporarily download the file and then check :)
I meant with header file simply a file which has all HTML top bit from web pages...Son
Link to comment
Share on other sites

I tried now all sort of combinations, nothing works... The only way to get the getimagesize function to work is to have two identical files (one to be included at root level and one a folder down) with only $path differing:$path = "images/"; (root level)$path = "../images/"; (for one folder down)Am not a fan of creating redundant data. Is there really now way to somehow reference an absolute path?Son

Link to comment
Share on other sites

Of course there's a way, you really think the solution is to duplicate the file? Does that make technical sense at all?If it works when you have a duplicate file, then you're actually referring to that duplicate file in your path. There are several things in $_SERVER you can use to get paths (look them up in a phpinfo page), or you can use one or more dirname functions with the __FILE__ constant to get an absolute path that's relative to the current script. e.g.:dirname(__FILE__); // current dirdirname(dirname(__FILE__)); // one level up

Link to comment
Share on other sites

Of course there's a way, you really think the solution is to duplicate the file? Does that make technical sense at all?If it works when you have a duplicate file, then you're actually referring to that duplicate file in your path. There are several things in $_SERVER you can use to get paths (look them up in a phpinfo page), or you can use one or more dirname functions with the __FILE__ constant to get an absolute path that's relative to the current script. e.g.:dirname(__FILE__); // current dirdirname(dirname(__FILE__)); // one level up
But I do not think that this is my problem. I had the absolute path hardcoded as (as it does not change)$path = http://www.domain.co.uk/images/which worked well to dynamically display the images themselves (so path is correct). Only that having the getimagesizefunction as:$size = getimagesize("$path$logo");or$size = getimagesize("{$path}{$logo}");does not work for root level and one level down files.When I remove the 'http://www.domain.co.uk/' and have$path = images/it works again for files at root level.Can you see where my problem lies?Son
Link to comment
Share on other sites

Are you trying to read a file outside of the web root? Can you give the real paths you're working with? If you give a relative path it's going to be a filesystem path relative to the current directory, which will open a file on the local server, not the remote server.

Link to comment
Share on other sites

Are you trying to read a file outside of the web root? Can you give the real paths you're working with? If you give a relative path it's going to be a filesystem path relative to the current directory, which will open a file on the local server, not the remote server.
Found my mistake in server root, left one folder out. But although the getimagesize function now works for all levels I am still a bit confused as in when to use the server root and when to use the http://-root as such. I still have two redundant files, which create a session for language choice. The line:if (isset($_GET['lang']) && ereg('[a-z]{2}(\-[a-z]{2})?', $_GET['lang']) && is_file("../inc/{$_GET['lang']}/general.php"))has again the same issue. If files are one level down this works, but for web root files it doesn't and I had a second file identical apart from the path bit.I tried now to use my server root variable, which is $absPath as (and which includes the slash at end):if (isset($_GET['lang']) && ereg('[a-z]{2}(\-[a-z]{2})?', $_GET['lang']) && is_file("$absPathinc/{$_GET['lang']}/general.php"))andif (isset($_GET['lang']) && ereg('[a-z]{2}(\-[a-z]{2})?', $_GET['lang']) && is_file("{$absPath}inc/{$_GET['lang']}/general.php"))and$incFiles = "inc/{$_GET['lang']}/general.php";if (isset($_GET['lang']) && ereg('[a-z]{2}(\-[a-z]{2})?', $_GET['lang']) && is_file($absPath . $incFiles))As the server path is working for getimagesize function I am now completely baffled why this is not working for my session file. Do you know why this is?SonReason for edit: Forgot to mention that $absPath has slash at end...
Link to comment
Share on other sites

All I can say is print the variables so you can see exactly what you're telling the code to do. Whenever you're having problems and you're confused by what the server is doing you should always be printing everything out and stepping through the code yourself.

Link to comment
Share on other sites

All I can say is print the variables so you can see exactly what you're telling the code to do. Whenever you're having problems and you're confused by what the server is doing you should always be printing everything out and stepping through the code yourself.
Thanks for your help. Have it working now:-)Son
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...