I try to load a other img when the first one is not loading.
<?php
$id2 = intval($_GET['id']);
$jpg = ".jpg";
$id = $id2 . $jpg;
$imagepath= $id;
$image=imagecreatefromjpeg( $imagepath);
header('Content-Type: image/jpeg');
imagejpeg($image);
?>
this loads my img when i have the id in /img
now i want to load a img with the same id when $imgsize = filesize( $id );
is 0.
from a external link like: http://xxxx.xx/getimg.php?id=28771
it should be easy with if else but i can't get it.
edit:
$id2 = intval($_GET['id']);
$jpg = ".jpg";
$id = $path . $id2 . $jpg;
if(isset($_GET['id']) && $_GET['id']!=0){
$id2 = intval($_GET['id']);
}
else{
$id2 = 1;
}
$imagepath= $id;
$image=imagecreatefromjpeg( $imagepath);
header('Content-Type: image/jpeg');
imagejpeg($image);
so this is the code I use now.
Try something like this considering that 1.jpg
is a default file in your imagepath folder
<?php
if(isset($_GET['id']) && $_GET['id']!=0){
$id2 = intval($_GET['id']);
}
else{
$id2 = 1;
}
?>
Something like this might solve your problem.This is just and idea you can modify the loops as per your need but i hope you got the overall idea.
if(isset($_GET['id']) && $_GET['id']!=0){
$id2 = intval($_GET['id']);
} else{
$id2 = 1;
}
$jpg = ".jpg";
$id = $path . $id2 . $jpg;
$imagepath= $id;
$image=imagecreatefromjpeg( $imagepath);
header('Content-Type: image/jpeg');
imagejpeg($image);
Use this code and tell me if it works or not
Another way to do it is in Javascript, there might be some scenarios where $_GET['id']
is set but the actual image is missing. This uses jquery.
$('img').error(function () {
if ($(this).hasClass("optional_class")) {
$(this).unbind("error").attr("src", "/no-picture.jpg");
} else {
$(this).remove();
}
});