php detect file attribute function

Some students are particularly curious about where to use file attribute detection. Detecting file attributes can be used in too many places.

Let’s give an example:

1. When we install the software, you will find that if the file exists, it will jump to another place.

2. If some files do not have write permission during the installation process, the installation will not be allowed.

Let’s take a screenshot of the installation process of discuz, a very famous software in China:

document_2015-09-07_55eda1ec1ab58.png

The above example is a typical file detection usage.

Let’s learn the following batch of functions. Then, let's learn through an example.

bool file_exists ($specify file name or file path)
Function: Whether the file exists.

bool is_readable ( $specifies the file name or file path)
Function: whether the file is readable

bool is_writeable ( $specifies the file name or file path)
Function: whether the file is writable

bool is_executable ($specifies the file name or file path)
Function: whether the file is executable

bool is_file ($specifies the file name or file path)
Function: whether it is a file

bool is_dir ($specifies the file name or file path)
Function: Whether it is a directory

void clearstatcache (void)
Function: Clear the status cache of the file

The above function can be seen at a glance Clear. As for the experiment, let’s write the example we gave at the beginning.

Let’s talk about the first example, file lock. If it has been installed, if the installation lock exists, it will prompt that it has been installed, otherwise, the installation will continue.

We assume that the URL of the installation interface is: install.php, and the installed lock file is install.lock. We can detect whether the install.lock file exists.

Let’s do a file installation detection experiment to detect whether the file or directory has write or read permissions. If not, the installation cannot be performed.

The ideas for handling this matter are as follows:

1. Define a batch of arrays that require permission detection

2. You can detect whether it is a folder or a file

3. Make a set bit variable. If the set bit variable is false, the next step of installation will not be displayed.

不可读'; } if(is_writeable($v)){ echo '可写'; }else{ echo '不可写'; } echo '
'; } if($flag){ echo '下一步'; }else{ echo '不能进行安装'; } ?>

Passed In the above example, we did it. Implement installation detection during the installation process of a certain PHP software.

This is the realization of our above ideas.


Continuing Learning
||
不可读'; } if(is_writeable($v)){ echo '可写'; }else{ echo '不可写'; } echo '
'; } if($flag){ echo '下一步'; }else{ echo '不能进行安装'; } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!