简体   繁体   中英

How to create a new folder using php

I am trying to create a new folder using PHP.

What I have so far:

$dir = dirname($_SERVER["REQUEST_URI"]).'/images/1/thumb'; 
if( is_dir($dir) === false )
    { 
        mkdir($dir, 0777, true);
    }

But the folder is not created. Any help would be appreciated.

You have to give absolute path as url will not work in file and directory handlig.

so your new function will be like that

   mkdir('./images/1/thumb', 0777, true);
<?php $structure = './images/1/thumb';

// To create the nested structure, the $recursive parameter 

// to mkdir() must be specified.

if (mkdir($structure, 0777, true)) {
echo "Folder Created";
}else{
echo "Not Created";

} ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM