php拾遗3

WBOY
Release: 2016-06-23 14:34:45
Original
818 people have browsed it

   今天 拾的是一些很好的PHP5里面的磁盘,文件方面的函数,
1)parse_ini_file,
   这个可以解析php样式的ini

[personal information]
name = "abc"
quest = tes
favorite color = csd
[status]
Gender = 男
Country = 中华人民共和国
  那么
    $file_array = parse_ini_file("my.ini");
    print_r($file_array);
?>
 这样的输出是没分段的,以array { [name]=>abc....}输出
要按部分输出INI文件的话,设置第二个参数为ini
        $file_array = parse_ini_file("my.ini", true);
    print_r($file_array);
?>

2) 统计某个目录的剩余空间
       $drive = "c:/windows";
    echo round((disk_free_space($drive) / 1048576), 2)."K字节";
?>
3) 显示磁盘的逻辑容量
        $systempartitions = array("c:", "d:","e:");
    foreach ($systempartitions as $partition) {
        $totalSpace = disk_total_space($partition) / 1048576;
        $usedSpace = $totalSpace - disk_free_space($partition) / 1048576;
        echo "分区: $partition (容量: $totalSpace MB. 已使用: $usedSpace MB.)
";
    }
?>

4) 计算文件大小 filesize()
      $file = "php_development.pdf";
    $bytes = filesize("$file");
    echo "文件名 ".basename($file)." 大小为 $bytes字节, 或 ".round($bytes / 1024, 2)." K字节.";
?>
5) 取得文件的建立,最后访问和更新时间
       $file = "demo.gif";
    echo "文件最后一次访问时间:".date("Y-m-d g:i:sa",  fileatime($file));
    echo "
文件建立时间: ".date("Y-m-d g:i:sa",  filectime($file));
    echo "
文件最后一次更新: ".date("y-m-d g:i:sa",  filemtime($file));
?>

 

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