开发者

PHP create folder with specific path and permissions

开发者 https://www.devze.com 2023-03-21 19:08 出处:网络
I need a way in PHP to create some folder if they do not exist. So the code will have to first read the available folders, if the specific folder does not exist then it should create it.

I need a way in PHP to create some folder if they do not exist.

So the code will have to first read the available folders, if the specific folder does not exist then it should create it.

The logic of the code w开发者_如何学Pythonould be:

$folderName = "user1";

If($folderName exists) {
exit;
}else{
create folder $folderName and chmod 777
}

How would I do it with PHP and Linux server + Apache?


$folderName = "user1";

if ( !file_exists($folderName) ) {
    mkdir($folderName);
}

In if statement we check if folder does not exist (yes - with file_exists function) and if not, we create folder.

777 chmod is by default.

0

精彩评论

暂无评论...
验证码 换一张
取 消