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

Summary of php file operations (delete specified files/get file names in folders/read image names in folders)_php skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 09:00:02
Original
1626 people have browsed it

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

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);
  }
}

Copy after login

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);
?>

Copy after login

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.

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template