Create a folder if it doesn’t already exist in PHP


You can check whether the folder is exits or not by using file_exists(). You can also create folder by using mkdir(). See below example code to create folder if it doesn’t already exits in PHP.

if (!file_exists('path/to/directory')) {
 mkdir('path/to/directory', 0777, true);

  • In the above example "path/to/directory" mean path of your folder
  • "077" permission of folder
  • mkdir php function for creating folder

Related Post

Latest Post

Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.