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

Function: whether the file exists.
Function: whether the file is readable
Function: whether the file is readable Writable
Function: whether the file is executable
Function: Whether it is a file
Function: whether it is a directory
Function: clear the status cache of the file
<?php
if(file_exists('install.lock')){
echo '已安装,请不要再次进行安装';
exit;
}
?> 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 idea of handling this matter is as follows: 1. Define a batch of arrays that need to detect permissions2. You can detect whether it is a folder or a file3. Make a set variable. If the set variable is false, the next step of installation will not be displayed. <?php
//可以定义一批文件是否存在
$files = [
'config.php',
'img/',
'uploads/',
];
//定义标志位变量
$flag = true;
foreach($files as $v){
echo $v;
//判断是文件还是文件夹
if(is_file($v)){
echo '是一个文件 ';
}else if(is_dir($v)){
echo '是一个文件夹 ';
}
if(is_readable($v)){
echo ' 可读';
}else{
echo '<font color="red">不可读</font>';
}
if(is_writeable($v)){
echo '可写';
}else{
echo '<font color="red">不可写</font>';
}
echo '<br />';
}
if($flag){
echo '<a href="step1">下一步</a>';
}else{
echo '不能进行安装';
}
?> Through the above example, we have done it. Implement installation detection during the installation process of a certain PHP software. This is the realization of our above ideas.
new file
<?php
//可以定义一批文件是否存在
$files = [
'config.php',
'img/',
'uploads/',
];
//定义标志位变量
$flag = true;
foreach($files as $v){
echo $v;
//判断是文件还是文件夹
if(is_file($v)){
echo '是一个文件 ';
}else if(is_dir($v)){
echo '是一个文件夹 ';
}
if(is_readable($v)){
echo ' 可读';
}else{
echo '<font color="red">不可读</font>';
}
if(is_writeable($v)){
echo '可写';
}else{
echo '<font color="red">不可写</font>';
}
echo '<br />';
}
if($flag){
echo '<a href="step1">下一步</a>';
}else{
echo '不能进行安装';
}
?>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















