简体   繁体   中英

PHP file_exists stopped working this morning?

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?

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.

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 Ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM