Home > Backend Development > PHP Tutorial > Summary of PHP file operations (delete the specified file/get the file name in the folder/read the image name in the folder), _PHP tutorial

Summary of PHP file operations (delete the specified file/get the file name in the folder/read the image name in the folder), _PHP tutorial

WBOY
Release: 2016-07-12 08:52:40
Original
665 people have browsed it

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

This article analyzes the methods of php file operations with 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

<&#63;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);
&#63;>

Copy after login

Readers who are interested in more PHP related content can check out the special topics of this site: "Summary of PHP File Operations", "Summary of PHP Operations and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Grammar" ", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "Introduction to PHP object-oriented programming tutorial", "Summary of PHP string (string) usage" , "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125903.htmlTechArticlephp file operation summary (delete specified file/get file name in folder/read picture name in folder) ), This article analyzes the methods of php file operation through examples. Share it with everyone for your reference...
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