zoukankan      html  css  js  c++  java
  • PHP_File文件操作简单常用函数

    php测试文件

    <?php 
    header("Content-type:text/html;charest=utf-8");
    $fileDir='Upload/File/content.txt';
    echo '文件路径:'.$fileDir.'<br/>';
    echo '路径目录|dirname():'.dirname($fileDir).'<br/>';
    echo '路径文件名|basename():'.basename($fileDir).'<br/>';
    echo '文件类型|filetype():'.filetype($fileDir).'<br/>';
    echo '文件大小|filesize():'.filesize($fileDir).'<br/>';
    echo '文件修改时间|filemtime():'.filemtime($fileDir).'<br/>';

    echo '<br/>';
    echo '绝对路径|realpath():'.realpath($fileDir).'<br/>';
    echo '以数组形式返回路径信息|pathinfo():<br/>';
    print_r(pathinfo($fileDir));echo '<br/>';
    echo '<br/>';

    echo '复制并重命名文件|rename(url01,url02):返回'.copy($fileDir,'./Upload/renameContent.txt').'<br/>';
    echo '复制文件|copy(url01,url02):返回'.copy($fileDir,'./Upload/copyContent.txt').'<br/>';
    echo '删除文件|unlink(url):返回'.@unlink('./Upload/unlinkContent.txt').'<br/>';

    echo '<br/>';
    echo '将文件信息以字符串形式读取出来|file_get_contents(url):<br/>';
    echo file_get_contents($fileDir).'<br/>';
    $putContent='hello word!';
    echo '将字符串写入文件,文件不存在自动创建,目录必须存在,|file_put_contents(url,str)返回文件大小:';
    echo file_put_contents('./Upload/file_put_contents.txt',$putContent).'<br/>';
    ?>

     

    php返回结果

    文件路径:Upload/File/content.txt
    路径目录|dirname():Upload/File
    路径文件名|basename():content.txt
    文件类型|filetype():file
    文件大小|filesize():27
    文件修改时间|filemtime():1411488282

    绝对路径|realpath():D:KuaipanwwwTestPhpUploadFilecontent.txt
    以数组形式返回路径信息|pathinfo():
    Array ( [dirname] => Upload/File [basename] => content.txt [extension] => txt [filename] => content )

    复制并重命名文件|rename(url01,url02):返回1
    复制文件|copy(url01,url02):返回1
    删除文件|unlink(url):返回

    将文件信息以字符串形式读取出来|file_get_contents(url):
    hello word! bad word!!!
    将字符串写入文件,文件不存在自动创建,目录必须存在,|file_put_contents(url,str)返回文件大小:11

  • 相关阅读:
    poj 1466 Girls and Boys (最大独立集)
    hdu 3667 Transportation (拆边 ,最小费用流)
    poj 3487 The Stable Marriage Problem (稳定婚姻 GaleShapley算法 )
    ZOJ Problem Set 1239 (最小点覆盖 )
    poj 2060 Taxi Cab Scheme (最小路径覆盖)
    poj 2226 Muddy Fields (最小点覆盖)
    hdu 1281 棋盘游戏 (二分图)
    hdu 3666 THE MATRIX PROBLEM (差分约束)
    poj 1325 Machine Schedule (最小点覆盖)
    ORACLE导入导出
  • 原文地址:https://www.cnblogs.com/workerman/p/4663284.html
Copyright © 2011-2022 走看看