Home >Backend Development >PHP Tutorial >Summary of php file operations (delete specified files/get file names in folders/read image names in folders)_php skills
this article analyzes the methods of php file operation through examples. share it with everyone for your reference, the details are as follows:
1. delete files
unlink()
syntax: int unlink(string filename);
return value: integer
function type: file access. such as:
unlink("tmp/test.txt");
2. get the file name under the folder
$dir = "message/"; // 文件夹的名称 if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo "文件名: $file <br>"; } closedir($dh); } }
3. read the image names under the folder
<?php $handle = opendir('images/'); //当前目录 while (false !== ($file = readdir($handle))) { //遍历该php文件所在目录 list($filesname,$kzm)=explode(".",$file);//获取扩展名 if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG") { //文件过滤 if (!is_dir('./'.$file)) { //文件夹过滤 $array[]=$file;//把符合条件的文件名存入数组 $i++;//记录图片总张数 } } } print_r($array); ?>
readers who are interested in more php-related content can check out the special topics on this site: "php file operation summary", "summary of php operations and operator usage", "php summary of network programming skills", "php basic syntax introductory tutorial", "summary of php office document operation skills (including word, excel, access, ppt)", " summary of php date and time usage", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation getting started tutorial" and "summary of common database operation skills in php"
i hope this article will be helpful to everyone in php programming.