Summarize what are the PHP file functions

一个新手
Release: 2023-03-16 13:00:02
Original
1867 people have browsed it

Simply organize some common functions for operating files in PHP:

  • filetype()  获取文件类型函数
    is_dir()  判断给定的文件名是否是一个目录  
    is_executable()  判断给定文件是否是可执行
    is_file()  判断给定文件是否存在
    is_link()  判断给定文件是一个符号链接(软链接)
    is_readable()  判断给定文件是否可读
    is_writeable()  判断给定文件是否可写
    file_exists()  判断文件或目录是否存在
    filesize()  获取文件大小(不能获取目录大小)
    filectime()  文件创建时间
    filemtime()   文件修改时间
    fileatime()  文件访问时间
    stat()  获取文件大部分参数
    basename($path,[$suffix]) 获取文件名
    $path URL地址
    $suffix  可选,规定扩展名,如果有此扩展名则不显示扩展名
    1 <?php2 3     $url = &#39;http://www.this.com/test/abc.php&#39;;4     echo basename($url);  // abc.php5     echo basename($url,&#39;.php&#39;); // abc      
    dirname($path)    获取路径地址
      $path  URL地址
    1 <?php2     echo dirname("http://www.cs.com/a/b/ab.php"); // http://www.cs.com/a/b
     
    pathinfo($path,[options])  获取路径信息
    $path      传入路径
    $option    规定返回数组元素,默认返回所有元素
     1 <?php 2       $path = &#39;http://localhost/a/b/ab.php&#39;; 3     print_r(pathinfo($path)); 4     // Array ( 
     5     //     &#39;dirname&#39; => &#39;http://localhost/a/b&#39;, 
     6     //     &#39;basename&#39; => &#39;ab.php&#39;, 
     7     //     &#39;extension&#39; => &#39;php&#39;, 
     8     //     &#39;filename&#39; => &#39;ab&#39; 
     9     //     ) 10     print_r(pathinfo($path,PATHINFO_DIRNAME)); //  http://localhost/a/b11     print_r(pathinfo($path,PATHINFO_BASENAME)); // ab.php12     print_r(pathinfo($path,PATHINFO_EXTENSION)); // php13     print_r(pathinfo($path,PATHINFO_FILENAME)); // ab 
     
    opendir()    打开一个目录,返回目录资源句柄
    readdir(&#39;资源句柄&#39;)   从目录中获取一个文件或目录,并指针向下移动一位
    closedir(&#39;资源句柄&#39;)  关闭打开的目录
    rewinddir(&#39;资源句柄&#39;)  将指针移动到首位
    disk_free_space(‘c:’)  返回指定目录可用空间
    disk_total_space(&#39;c:&#39;)  返回指定目录共计大小
    mkdir()   创建一个目录
    rmdir()   删除一个目录
    unlink()  删除一个文件  返回bool值
    copy()   复制文件  不支持复制目录
    Copy after login

The above is the detailed content of Summarize what are the PHP file functions. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!