Jump to content

IF/THEN with Image


mcmuney

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443120
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/86608-ifthen-with-image/#findComment-443136
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.