Question

Just wondered, I have the following code:

            <a href="<?=$row->aw_deep_link?>">
                <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . 'images/products/' . $row->strId . '.jpg')):?>

                <img alt="<?=$row->my_brand . ' ' . $row->line . ' ' . $row->my_product . ' - ' . $row->size.$row->unit?>" height="170" itemprop="image" src="<?=base_url() . 'images/products/' . $row->strId?>.jpg" width="170">
                <?php else:?>

                <img alt="<?=$row->my_brand . ' ' . $row->line . ' ' . $row->my_product . ' - ' . $row->size.$row->unit?>" height="170" itemprop="image" src="<?=$row->aw_image_url?>" width="170">
                <?php endif;?>

            </a>

Up until last night, this was performing perfectly; this morning - it's stopped, out of the blue and automatically defaults to the

else

clause.

Has something changed with PHP?

Was it helpful?

Solution 2

If no files or scripts were changed that you know of (including if the image file is still actually there) then it could have been a server change / update which has caused an error.

My suggestion would be to run some simple tests in a separate file I.e. check the value of your $_SERVER['DOCUMENT_ROOT'] variable, check for the existence of the directory containing your image, then check for the existence of the image.

If you're 100% sure you have changed nothing on the server, I'd suggest contacting your host.

OTHER TIPS

You don't give enough info for anyone to give you the answer, but I would suggest checking:

  1. Does $_SERVER['DOCUMENT_ROOT'] still equal what you expect? You could use echo $_SERVER['DOCUMENT_ROOT']; to find out.
  2. Does the images/products/ directory still exist and is it readable by the user that is running this php script? Which is probably the user that Apache is running as.
  3. Is $row->strId still valid?
  4. Are there some files called $row->strId.jpg in the directory and are they readable by your user?

Assuming that file_exists is broken is the wrong place to start, check your variables that are being used to construct the file name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top