kcraighead Posted March 14, 2006 Posted March 14, 2006 I have a php script which checks to see if an image exists by using "@GetImageSize". If a value is returned then the image is displayed, if not a different image saying "no picture on file" appears. I have used this on 3 different websites and all of them have worked perfectly until today. On ALL of them I now get "no picture on file" as though the "@GetImageSize" function I have been using has suddenly stopped working. Previously all of the pictures have been showing fine. I have checked my webpages and php scripts and they are unchanged and all of the images are in the right place on all of the websites. This lead me to conclude that something has changed on my reseller account that has stopped this function working. Anyone got any ideas? Here is a copy of the php script I use: $path = "http://www.myaccount.com/images/properties/self_catering/"; $file = "sc_".$row['picture_id'].".jpg"; $desc = "Link to ".$row['property_name']; $noimage = "no_image"; //check if image exists if($img = @GetImageSize("$path$file")) { echo "<td width='150' height='100' align='left' valign='top'><a href='self_catering_detail.php?propertyid=".$row['property_id']."&propertyname=".$row['property_name']."&nearesttown=".$nearesttown."'> <img src=$path$file alt='$desc' title='$desc' width='150' height='98' border='0'></a></td>"; } else { echo "<td width='150' height='100' align='left' valign='top'><a href='self_catering_detail.php?propertyid=".$row['property_id']."&propertyname=".$row['property_name']."&nearesttown=".$nearesttown."'> <img src='$path$noimage.gif' alt='$desc' title='$desc' width='150' height='98' border='0'></a></td>"; } Edit: TCH-Bruce removed account information Quote
TCH-Bruce Posted March 14, 2006 Posted March 14, 2006 If it has suddenly stopped working and you have not changed anything please open a ticket with the help desk and have the techs have a look. Link at top of page or in my signature. Quote
kcraighead Posted March 14, 2006 Author Posted March 14, 2006 If it has suddenly stopped working and you have not changed anything please open a ticket with the help desk and have the techs have a look. Link at top of page or in my signature. Techs tell me: "Please be advised that the help desk does not provide developer level support for the coding of web pages, html code, php code, cgi code, graphics, sql backend or any other programming or design elements." Anyone else got any ideas? Quote
TCH-Tim Posted March 14, 2006 Posted March 14, 2006 (edited) I wrote a little test to make sure getimagesize() works on my server (59): ><?php $img = @getimagesize("menu.jpg"); if ($img) { echo "okay"; } else { echo "no way"; } ?> If menu.jpg is there then $img has a value and I get "okay." If it's not, $img is empty and doesn't pass the if(), so I get "no way." Looking at your code, I fail to see where $img is defined, so I wouldn't expect it to equal the output of getimagesize(). Am I missing something? Edited March 14, 2006 by timhodge Quote
TCH-Tim Posted March 14, 2006 Posted March 14, 2006 I took your code and stripped out some stuff to test my previous statement about $img not being defined. (Sorry, still a bit of a noob at some of this stuff.) Used this: ><?php $path = "http://www.garduque.net/test/"; $file = $pic.".jpg"; //check if image exists if($img = @GetImageSize("$path$file")) { echo "okay"; } else { echo "no way"; } ?> and passed the $pic variable in the URL and it works. So I guess I'm not sure what your problem is. Might be worth checking what it's putting out for $file. Quote
kcraighead Posted March 14, 2006 Author Posted March 14, 2006 I have found the solution! Thanks for all the suggestions - getting back to basics was what got me to the solution. As ever, it was simple. Basically the absolute path "http://www.whatever.com/images/etc" stopped working. If I replaced them with the relative path "/images/etc/" it worked. The only remaining issues is why absolute paths fail to find the files when they worked perfectly previously? For now I have to go round and do lots of link replacements on my websites... Cheers! Quote
TCH-Tim Posted March 14, 2006 Posted March 14, 2006 That's weird that absolute paths don't work. It did in my second example. If the paths exist, and the images exist, and you have permission to access the images, then it should be fine. Might be worth it to echo $path$file just to see what the script thinks it's looking for. Might be something simple and save you from changing all your links. Glad you got it working anyway. Quote
TCH-Bruce Posted March 14, 2006 Posted March 14, 2006 That's weird that absolute paths don't work The absolute path does not begin with "http:" it would be >/home/cpanel-name/public_html/path-to-file Quote
rnmcd Posted December 22, 2007 Posted December 22, 2007 The absolute path does not begin with "http:" it would be >/home/cpanel-name/public_html/path-to-file What is the difference between the "relative path" and the "absolute path"? Quote
TCH-Andy Posted December 22, 2007 Posted December 22, 2007 As an example, if you are currently in your public_html folder and you are trying to get to a file called test.jpg in the images folder ( which is itself in the public_html folder) then; The relative path would be images/test.jpg The absolute path ( for a php script) would be /home/user/public_html/images/test.jpg The absolute path starts with a '/' and shows the complete path from the beginning, whereas the relative path is just from where you currently are. Quote
rnmcd Posted December 24, 2007 Posted December 24, 2007 Is there an advantage/disadvantage of using a relative/absolute path instead of the URL to the file? Quote
TCH-Bruce Posted December 24, 2007 Posted December 24, 2007 The advantage of using relative paths is you can move it from folder to folder or host to host and you wouldn't have to change anything. With absolute paths, if your home path changes you need to modify your code. Quote
rnmcd Posted December 25, 2007 Posted December 25, 2007 So would there be a situation you can think of where you would want to use an absolute path? It seems that the relative path will always get you to your specified file. Also, in this absolute path: /home/user/public_html/images/test.jpg Is "home" the actual text to be used for paths on TCH servers? I can't seem to get absolute paths to work for me. I understand that "user" is my cpanel username. Quote
TCH-Bruce Posted December 25, 2007 Posted December 25, 2007 Log into your cPanel. In the left sidebar your Home Directory path is displayed. Most servers are set up /home/cpanelname And when entering an absolute path there is no http:// Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.