Reputation: 39
I am a php newbie so please go easy.
I created queries for imgFld and imageFldName. I am trying to find why my images from my db are not being displayed.
I have the below code:
image_show(stripslashes($row['imgFld']),stripslashes($row['imageFldName']));
echo ' '.$records_num;
function image_show($name_image, $alt_tag) {
if (file_exists("mywebsite.co.uk/images/'$name_image'")) {
$img = getimagesize('mywebsite.co.uk/images/'.$name_image);
echo '<img src="mywebsite.co.uk/images/'.$name_image.'" alt = '.$alt_tag.' border=0 align="bottom"';
echo 'width = '. $img[0] .' height = ' .$img[1] . ' />';
} else {
echo 'Add an image here';
}
}
Im getting the image names from a column inside my db and each column has an 'image.jpg', connecting it with the img src script from HTML so that I can display the images from the db.
However no images are being displayed and I cant find the error. Doesnt seem like anything is wrong. When I echo $name_image nothing is produced.
Upvotes: 2
Views: 87
Reputation: 4179
In that case it means that there is nothing populating the $name_image
variable.
Assuming that website directory is a local one, the cause of this is most likely your arguments when you call the image_show
function. They do not match the order you have specified.
The first argument should be the name and the second the alt text, as defined:
function image_show($name_image, $alt_tag)
However you are passing the id to $name_image
and the name as $alt_tag
.
That should be it.
Upvotes: 1
Reputation: 1492
The problem is file_exists is only for local files.
For example:
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/path/to/files/image.jpg')) {
...
}
Upvotes: 0