简体   繁体   中英

How to use file_exists function for a directory outside of current folder?

I'm trying to check whether an image file (.jpg) exists using file_exists for a directory which is outside of the current file directory.

Diagram of file system

Image Directory
Websites -> GetaShoe -> 190 -> Image file 
websites/WEBSITE1/190/123.jpg

Current Directory
Websites -> Shoesgb -> current directory
websites/WEBSITE2/currentpage.php

So how would I check whether a file exists within the image directory when using file_exists within the current directory?

I've tried the following:

<?php

     $filename = '/GetAShoe/190/123.jpg';

     if (file_exists($filename)) { echo 'Found'; } else { echo 'Not Found'; }

?>

This doesn't work as no images are found at all within a directory of 1000's images.

Can anybody advise on the correct way to refer to an external file path?

Thanks

Try using a relative pathname to the image directory. / starts you at your computer root. As Marc said: ../GetAShoe will probably work.

The solution was the use the ABSOLUTE file path, which I found using __FILE__

So the correct path was :

<?php 

$filename = "/root/26/987654321/htdocs/websites/WEBSITE/190/$info[product_id].jpg"; 

if (file_exists($filename)) { echo 'Found'; } else { echo 'Not Found'; }

?>

Note actual file path has been altered for security reasons, the path provided above is for illustrative purposes.

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