Php Script Does Not Show Images Any More

liunx

Guest
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.<br /><br />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?<br /><br />Here is a copy of the php script I use:<br /><br />$path = "http://www.myaccount.com/images/properties/self_catering/";<br />$file = "sc_".$row['picture_id'].".jpg";<br />$desc = "Link to ".$row['property_name'];<br />$noimage = "no_image";<br /><br />//check if image exists<br />if($img = @GetImageSize("$path$file"))<br />{<br />echo "<td width='150' height='100' align='left' valign='top'><a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/'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>";<br />}<br />else<br />{<br />echo "<td width='150' height='100' align='left' valign='top'><a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/'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>";<br />}<br /><br /><br /><!--coloro:#3366FF--><span style="color:#3366FF"><!--/coloro--><!--sizeo:1--><span style="font-size:8pt;line-height:100%"><!--/sizeo-->Edit: TCH-Bruce removed account information<!--sizec--></span><!--/sizec--><!--colorc--></span><!--/colorc--><!--content-->
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.<!--content-->
<!--quoteo(post=169691:date=Mar 14 2006, 08:16 AM:name=TCH-Bruce)--><div class='quotetop'>QUOTE(TCH-Bruce @ Mar 14 2006, 08:16 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=169691"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->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.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Techs tell me:<br /><br />"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."<br /><br />Anyone else got any ideas?<!--content-->
I wrote a little test to make sure getimagesize() works on my server (59):<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$img = @getimagesize("menu.jpg");<br />if ($img) {<br />    echo "okay";<br />} else {<br />    echo "no way";<br />}<br />?><!--c2--></div><!--ec2--><br />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."<br /><br />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?<!--content-->
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:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$path = "http://www.garduque.net/test/";<br />$file = $pic.".jpg";<br /><br />//check if image exists<br />if($img = @GetImageSize("$path$file"))<br />{<br />echo "okay";<br />}<br />else<br />{<br />echo "no way";<br />}<br />?><!--c2--></div><!--ec2--><br />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.<!--content-->
I have found the solution! Thanks for all the suggestions - getting back to basics was what got me to the solution. <br /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> <br /><br />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.<br /><br />The only remaining issues is why absolute paths fail to find the files when they worked perfectly previously?<br /><br />For now I have to go round and do lots of link replacements on my websites...<br /><br />Cheers!<br /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
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.<br /><br />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.<br /><br />Glad you got it working anyway.<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->That's weird that absolute paths don't work<!--QuoteEnd--></div><!--QuoteEEnd--><br />The absolute path does not begin with "http:" it would be<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/home/cpanel-name/public_html/path-to-file<!--c2--></div><!--ec2--><!--content-->
<!--quoteo(post=169754:date=Mar 14 2006, 01:06 PM:name=TCH-Bruce)--><div class='quotetop'>QUOTE (TCH-Bruce @ Mar 14 2006, 01:06 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=169754"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->The absolute path does not begin with "http:" it would be<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/home/cpanel-name/public_html/path-to-file<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd--><br />What is the difference between the "relative path" and the "absolute path"?<!--content-->
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; <br /><br />The relative path would be images/test.jpg <br /><br />The absolute path ( for a php script) would be /home/user/public_html/images/test.jpg <br /><br />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.<!--content-->
Is there an advantage/disadvantage of using a relative/absolute path instead of the URL to the file?<!--content-->
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.<!--content-->
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.<br /><br />Also, in this absolute path: /home/user/public_html/images/test.jpg <br />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.<!--content-->
Log into your cPanel. In the left sidebar your Home Directory path is displayed. Most servers are set up /home/cpanelname <br /><br />And when entering an absolute path there is no <!--coloro:blue--><span style="color:blue"><!--/coloro-->http://<!--colorc--></span><!--/colorc--><!--content-->
 
Back
Top