2

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.

2
  • 1
    shouldn't you add http:// before the image location? :) Commented Jan 29, 2013 at 12:28
  • the image location is a local static folder Commented Jan 29, 2013 at 12:47

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is file_exists is only for local files.

For example:

if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/path/to/files/image.jpg')) {
...
}

2 Comments

the directory of the images is local..I had given it a fake name to post on here. The directory is not mywebsite.co.uk
another typo ? hehe... try to use this, including documen_root. Greatings!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.