View Full Version : getimagesize() and subdomain, error returned
I've been reading the problem others been having with their php script and getimagesize(). I don't know a lot about PHP, please assume I know nothing except how to read step-by-step instructions!
Basically, I'm running wordpress v1.5 @ http://blog.rodtv.com and with the beautiful plugin called iimage gallery (http://fredfred.net/skriker/index.php/iimage-gallery), I can create galleries effortlessly.
I just changed my webhosting company from HostExcellence to PowWeb. And I discovered that the plugin no longer work for new posts. It basically hangs for about 2 minutes, and spits out error as if the image files aren't there at all. The old galleries work just fine -- so it's something to do with getimagesize() (it calls this when creating thumbnails)
After browsing the forum for a while, I found several others with the same problem. One gave a solution (http://forum.powweb.com/showthread.php?t=43890&highlight=getimagesize) but it doesn't work for me. Sticking in "localhost" infront of my subdomain ie "http://localhost.subdomain.domain.com" doesn't work =(
So, to give another spin at this issue, please take a look at this code (http://blog.rodtv.com/wp-content/plugins/troublemaker.php_) then try running it (http://blog.rodtv.com/wp-content/plugins/troublemaker.php). When you're runningn the code, give it 5 minutes or so before it'd spit out answers.
I would like a simple solution if possible! Thanks for any help!
mitchind
6-10-05, 06:24 PM
So, to give another spin at this issue, please take a look at this code (http://blog.rodtv.com/wp-content/plugins/troublemaker.php_) then try running it (http://blog.rodtv.com/wp-content/plugins/troublemaker.php). When you're runningn the code, give it 5 minutes or so before it'd spit out answers.
Your images don't exist on the URL you gave - so not much to go by
Your images don't exist on the URL you gave - so not much to go by
<html>
<head></head>
<body>
This section loads the image from my website <br><br>
<?php
$file = 'http://blog.rodtv.com/images/general/my_life/research_-_imaginal_discs_002.jpg';
$type = getimagesize($file);
if($type == false){
echo $file.' is not accessible or supported filetype.';
}
else {
echo "We can work with ".$file;
echo "<br />We have got this: ".$type[3];
}
?>
<br /><img src="<?php echo $file;?>" />
<br />
<hr />
This section loads the image from a remote site <br><br>
<?php
$file = 'http://img179.echo.cx/img179/1910/researchimaginaldiscs0028ge.jpg';
$type = getimagesize($file);
if($type == false){
echo $file.' is not accessible or supported filetype.';
}
else {
echo "We can work with ".$file;
echo "<br />We have got this: ".$type[3];
}
?>
<br /><img src="<?php echo $file;?>" />
<br />
<hr />
This section adds "localhost" into the equation on the local site<br><br>
<?php
$file = 'http://localhost.blog.rodtv.com/images/general/my_life/research_-_imaginal_discs_002.jpg';
$type = getimagesize($file);
if($type == false){
echo $file.' is not accessible or supported filetype.';
}
else {
echo "We can work with ".$file;
echo "<br />We have got this: ".$type[3];
}
?>
<br /><img src="<?php echo $file;?>" />
</body>
</html>
the images are @ http://blog.rodtv.com/images/general/my_life/research_-_imaginal_discs_002.jpg
http://img179.echo.cx/img179/1910/researchimaginaldiscs0028ge.jpg
Actually, I just discovered that localhost might not be a good solution. I need something that's... more elaborate I suppose =(
RTH10260
6-10-05, 06:42 PM
I've been reading the problem others been having with their php script and getimagesize(). I don't know a lot about PHP, please assume I know nothing except how to read step-by-step instructions!The script shouldn't be reading the image using the http wrapper and an url when the file is local.
GETIMAGESIZE() should be using the local file system path within your account:GETIMAGESIZE($_SERVER['DOCUMENT_ROOT'].'/pathto/filename')
using part of your last sample:$file = '/images/general/my_life/research_-_imaginal_discs_002.jpg';
$type = getimagesize($_SERVER['DOCUMENT_ROOT'].$file);
RTH10260
6-10-05, 07:08 PM
It works! I think...
You just edited when I intended to tell you that $_SERVER['DOCUMENT_ROOT'] resolves to your account path '/www/d/o/domain.com/htdocs' !
Hint: use this snippet to display the internals:<? phpinfo(); ?>
You're my saviour! I been sitting in front of my computer for the past 5 hours since I discovered the problem trying to find a solution and you did it! I went into the gallery plugin script, and basically tacked on "$_SERVER['DOCUMENT_ROOT']." to every "@file" and it works great!
Well, I don't think I'd be able to make a gallery for images from other websites now.. oh well. Maybe in the future, I can learn enough about PHP to figure out how to do an "IF" statement that depends if @file starts with http --- it'd just let it go as normal, and if not, it'd tack the server['document_root'] in front.
Thanks so much, RTH10260, you really helped me out a bunch!
RTH10260
6-10-05, 11:40 PM
Well, I don't think I'd be able to make a gallery for images from other websites now.. oh well. Maybe in the future, I can learn enough about PHP to figure out how to do an "IF" statement that depends if @file starts with http --- it'd just let it go as normal, and if not, it'd tack the server['document_root'] in front.The magic you are looking for is this:<?
$fileinfo = parse_url($file);
if ( $fileinfo['host'] == $_SERVER['HTTP_HOST'] ) {
// local file system access, assumes no url rewriting
$type = getimagesize($_SERVER['DOCUMENT_ROOT'].$fileinfo['path']);
} else {
// uses http wrapper with the url provided
$type = getimagesize($file);
}
?>
The magic you are looking for is this:<?
$fileinfo = parse_url($file);
if ( $fileinfo['host'] == $_SERVER['HTTP_HOST'] ) {
// local file system access, assumes no url rewriting
$type = getimagesize($_SERVER['DOCUMENT_ROOT'].$fileinfo['path']);
} else {
// uses http wrapper with the url provided
$type = getimagesize($file);
}
?>
After I wrote what I did 3 days ago, I did a ghetto implementation with the following to get by... (the regex isn't what I used I think... but I already overwrote mine with yours)
if (!preg_match('/(http:/\/\)/i', $file) {
$file = $_SERVER['DOCUMENT_ROOT'].$file;
}
Yours is a much better implementation!
variable
6-15-05, 03:13 PM
i had the same problem, this deffinatly sped the whole process up. it still takes about 5 seconds to load though. is this because of external pics?
RTH10260
6-15-05, 04:53 PM
is this because of external pics?Very likely. First the server script gets the image file over the web to determine the information details, and then the clients browser reads the file a second time for rendering.
variable
6-15-05, 11:49 PM
i.c. so would it be a wise choice to have any images displayed be local(ie. have an upload form for any pictures users want on the site?)
or is there some way for php to see the width and height of a picture on another site without having to download the entire picture?
RTH10260
6-16-05, 07:16 AM
i.c. so would it be a wise choice to have any images displayed be local(ie. have an upload form for any pictures users want on the site?)
or is there some way for php to see the width and height of a picture on another site without having to download the entire picture?There is no definitive answer to your questions.
The internal details of the getimagesize() function are not described, they are of no interest as far as the API interface is concerned. One would have to check with the implementation of getimagesize(), PHP is open soure, so that would be available. The efficency cannot be determined alone by the code, networking latency plays a major part on actual lapsed time, and this can vary vastly.
My preference would be to store the getimageisze() information in a local database, and hope that the image file remains static (eg is not replaced with different content under the same name). The database gets either loaded when the gallery is built with new URLs or on first request. The gallery software would first consult the cache for the information, and if not available, would use the php function. If I want to play it to the safe side, I would refresh the cache information from time to time (several scenarios possible for that).
variable
6-19-05, 12:30 AM
i did the cached image scenario you posted and now it loads extremely quickly, i will just make a button in the admin interface to refresh the pics info.
vBulletin v3.6.0, Copyright ©2000-2010, Jelsoft Enterprises Ltd.