Search code examples
phpfile-exists

PHP - How to check a subfolder for a single file?


    $code="524";
    $filepath="/assets/$code/";
    $file="";
    if(@fopen($path,"r")){

        // code
// replace function here (ill do this)

    }

echo '<a href="link.php?go=$file">your colour is: </a>';
  • /assets/542
  • /assets/542_blush/
  • /assets/542_blush/542_blush.jpg

At the moment, the code is always going to be 3 digits, it will always have a subfolder with only an underscore and color and then inside that one file..


Solution

  • PHP has a file_exists() function;

    if ( file_exists( '/assets/' . $code . '_blush/' . $code . '_blush.jpg' ) ) {
        // ...
    }