Currently, users can upload images to my site, and the location of the image is stored in a MySQL table.
When I call images using the SELECT function, they are loaded via the CSS style background-image: url ('image.jpg')
Currently, I have used the IF statement, which places a placeholder image in place of any rows for which the "Image_URL" column is set to NULL.
if ($row["Image"] != "") {
echo "<td width='200' rowspan='3'><center><a href='/uploads/".$row["Image"]."' target='_blank'><div class='image-cropper'><div class='rounded' style='background-image:url(\"/uploads/".$row["Image"]."\")'>";
} else {
echo "<td width='200' rowspan='3'><center><a><div class='image-cropper'><div class='rounded' style='background-image:url(\"/images/no-image.jpg\")'";
}
My method, however, does not work for erroneous links (where the original image was deleted or the link is incorrect for some reason.) It just shows a space, and I understand why, because $ row ["Image"]! = NULL , there is a link, it is simply not connected with the image.
Is there a way to upload an image with a no-image.jpg sample when the image is not found on the provided link?
My DIVs are just making my images circular and centered, so I will post them here, if that helps, you can help me adapt these classes to add placeholder functionality.
.image-cropper {
max-width: 150px;
height: auto;
position: relative;
overflow: hidden;
}
.rounded {
display: block;
margin: 0 auto;
height: 150px;
width: 150px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
background:center no-repeat;
background-size:cover;
}
The cropping image and the rounded DIV are actually from this site, so thanks Hiral !