user188962
user188962

Reputation:

How come sometimes images wont show when using the full path?

I have this php code:

$images=array();
    $root = $_SERVER['DOCUMENT_ROOT'].'SV';
    for ($i=1; $i<=$total_pics; $i++){
        $images[]=$root.'/ad_images/'.$category.'/thumbs/'.$id_stripped.'_'.$i.'.jpg';
    }

And here I display the image:

<?php for ($n=1; $n<count($images); $n++): ?><img src="<?php echo $images[$n];?>"><?php endfor; ?>

But this wont show the image, only a square-box that shows when image is not found.

When I click on properties on the box, the full path is actually correct, and the image file IS THERE, but it act as if it is not there.

HOWEVER, when I use the relative path, it works just fine! Why?

Thanks

Upvotes: 1

Views: 872

Answers (2)

dw.
dw.

Reputation: 11

Typically $_SERVER['DOCUMENT_ROOT'] shows the file system path and not the web server path.

When you use a relative path, it's from the web root of the site.

Upvotes: 1

Matt
Matt

Reputation: 44058

What is the HTML output? If you're using an absolute path, I would imagine the output looks something like this (on a linux server):

<img src= "/var/www/path/to/image.jpg"/>

Which wouldn't work unless you used the file:// prefix:

<img src="file:///var/www/path/to/image.jpg"/>

And even then, it would only work on a local browser.

Upvotes: 2

Related Questions