The Web Blinders logo

Programming

PHP - How to check if a file or directory already exists

<?php

 // directory path or file name
 // For eg: 2019/11
 // or 2019/11/photo.png
 $directoryPath = "2019/11";


 if(!file_exists($directoryPath)){
     exit("{$directoryPath} doesn't exist");
 }
 exit("{$directoryPath} exists");
 // you could use ternary operator

file_exists() can be used to check if a file or folder exists

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES