Sujay U N Sujay U N - 3 months ago 12
PHP Question

Php: Iterate over dir path and create folder if not exist

I want to make sure each folder in path exist.

$Path = "NamFdr1/NamFdr2/NamFdr3/NamImj.jpg"


  • First check that
    exists, if not create it;

  • Then check that
    exists, if not create; and so on.

How can I do this with built-in functions?


try this,

 if (!file_exists('NamFdr1/NamFdr2/NamFdr3')) 
     mkdir('NamFdr1/NamFdr2/NamFdr3', 0777, true);

i hope it will be helpful