How to set up php directory

藏色散人
Release: 2023-03-07 16:28:02
Original
2634 people have browsed it

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 ]]] )
Copy after login

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');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!