Sujay U N Sujay U N - 1 year ago 118
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?

Answer Source

try this,

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

i hope it will be helpful

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download