mcmuney Posted January 18, 2008 Share Posted January 18, 2008 Is there a way to determine if an image that included on a page is a good link or a bad link? I'd like to use an if/then statement to redirect users if the image on the page is a bad link. Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/ Share on other sites More sharing options...
vbnullchar Posted January 18, 2008 Share Posted January 18, 2008 javascript? Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-442607 Share on other sites More sharing options...
pdkv2 Posted January 18, 2008 Share Posted January 18, 2008 i am not getting what exactly you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-442636 Share on other sites More sharing options...
mcmuney Posted January 18, 2008 Author Share Posted January 18, 2008 Basically, I have a php page, which shows an image based on the id attached to the link. For example, page.php?image_id=123, this page will display 123.jpg on that page. Now lets say that this image is removed or the file is corrupted. Now when people visit page.php?image_id=123, it'll simply show a bad image link. What I want to do is use an if/then statement to redirect the user if the image link/path is bad. Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443120 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 Not sure how you can check if it's corrupt or not, but you can check if the file exists. http://www.php.net/function.file-exists Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443123 Share on other sites More sharing options...
ratcateme Posted January 19, 2008 Share Posted January 19, 2008 you could create a script with php GD to load the image e.g. page.php: <?php function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreatetruecolor(300, 30); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 300, 30, $bgc); /* Output an errmsg */ imagestring($im, 16, 5, 5, "Error loading $imgname", $tc); } return $im; } header("Content-Type: image/jpeg"); $img = LoadJpeg($_GET['image_id'].".jpg"); imagejpeg($img); ?> Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443136 Share on other sites More sharing options...
Mirkules Posted January 19, 2008 Share Posted January 19, 2008 You can also use file headers to verify the image: http://www.mikekunz.com/image_file_header.html Quote Link to comment https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443147 Share on other sites More sharing options...
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.