PHP images from function

I am new to php, so please go through.

I have created requests for imgFld and imageFldName. I am trying to find why my images from my db are not showing.

I have 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 image names from a column inside my db and each column has "image.jpg" connecting it to an img src script from HTML so that I can display images from the db.

However, the images are not showing and I cannot find the error. It seems that something is wrong. When I echo $ name_image nothing gets created.

+3


source to share


2 answers


In this case, it means that nothing is being populated by the variable $name_image

.

Assuming the website directory is local, this is most likely due to your arguments when you call the function image_show

. They are not in the order you specified.

The first argument must be the name and the second alt text, as defined:



function image_show($name_image, $alt_tag)

      

However, you are passing id to $name_image

and name as $alt_tag

.

It should be.

+1


source


The file_exists issue is only for local files.

For example:



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

      

0


source







All Articles