开发者

How to create a directory with PHP?

开发者 https://www.devze.com 2023-03-27 20:17 出处:网络
In my php web page I want to create a directory under the current directory ( __DIR__ or dirname(__FILE__) ). How to achieve tha开发者_开发知识库t ?With the mkdir function.,http://php.net/manual/en/fu

In my php web page I want to create a directory under the current directory ( __DIR__ or dirname(__FILE__) ). How to achieve tha开发者_开发知识库t ?


With the mkdir function.,


http://php.net/manual/en/function.mkdir.php

mkdir("/path/to/dir", 0700);  // Linux

mkdir("c:/path/to/dir"); // Windows - windoes ignore modes

Also on windows note the slash direction is not as you'd expect :)

EDIT

To detect if Windows/Linux:

$os_string = php_uname('s');
if (strpos(strtoupper($os_string), 'WIN')!==false) {
    echo 'Windows';
} else {
    echo 'Linux';
}

You may also need to play with $_SERVER['DOCUMENT_ROOT'] to determine the paths.


Use PHP's mkdir() function. Make sure to test for errors too:

if (!mkdir('directory')) { //ERROR! Directory not created! }


Use the build-in php function mkdir.


mkdir(__DIR__.'/'.$dir_name); 

See also: http://php.net/mkdir

0

精彩评论

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