Snippet
Using the file_exists function it is very easy to check whether a file exists in a given directory or not. Say we want to check if file name audio.mp3 exists or not in /tmp folder.

  1. <?php
  2. $filename = '/tmp/audio.mp3';
  3.  
  4. if (file_exists($filename)) {
  5. echo "The file $filename exists";
  6. } else {
  7. echo "The file $filename does not exist";
  8. }
  9. ?>