Sujay U N Sujay U N - 5 months ago 14
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"


E.g.:


  • First check that
    "NamFdr1"
    exists, if not create it;

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



How can I do this with built-in functions?

Answer

try this,

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

i hope it will be helpful