Home >Backend Development >PHP Problem >How to set up php directory

How to set up php directory

藏色散人
藏色散人Original
2020-11-18 09:06:592684browse

How to set the directory in php: first create a PHP sample file; then create the directory through the "mkdir('test',0644)" function; and finally set the relevant permission parameters.

How to set up php directory

The operating environment of this tutorial: windows10 system, php5.6. This article is applicable to all brands of computers.

Recommended: "PHP Video Tutorial"

php setting directory:

Create and delete directories

1.mkdir(' test',0644): Create directory

bool mkdir ( string pathname [, intpathname[,intmode = 0777 [, bool recursive = false [, resourcerecursive=false[,resourcecontext ]]] )

Note: $mode is the permission. Users, groups, and other users each have permissions of r=4/w=2/x=1, such as 0644 is rw_/r__ /r__ (Knowledge of Linux permissions)

2.rmdir('test'): Delete the directory. Note that the directory must be empty

3.unlink('test.php'): Delete the file

4. Use recursion to delete non-empty directories, as follows:

**注:切记排除目录下的.和..,否则会删除整个磁盘内容,且不进回收站!**
    function deleteDir($dirname){
        $dir=opendir($dirname);
        while($filename=readdir($dir)){
            if($filename!=='.'&&$filename!=='..'){
                $filename=$dirname.'/'.$filename;
                if(is_dir($filename)){
                    deleteDir($filename);
                }else{
                    unlink($filename);
                }
            }
    
        }    
            
        closedir($dir);
        rmdir($dirname);
    }
    deleteDir('test');

The above is the detailed content of How to set up php directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn