zoukankan      html  css  js  c++  java
  • php文件删除unlink()详解

    请记住从PHP文件创建的教训,我们创建了一个文件,名为testFile.txt 。

    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fclose($fh);
    判断是否删除了. http://www.manongjc.com/article/1351.html
    $myFile = "testFile.txt";
    unlink($myFile);

    $filename = 'file.txt';
    fopen($filename,'a+');
    if(!unlink($filename))
    {
    echo "文件{$filename}删除失败"; //  http://www.manongjc.com/article/1351.html
    }
    else
    {
    echo "文件{$filename}删除成功";
    }
    ?>

    删除目录下所有文件

    function delFileUnderDir( $dirName="../Smarty/templates/templates_c" )
    {
    // http://www.manongjc.com/article/1351.html
    if ( $handle = opendir( "$dirName" ) ) {
       while ( false !== ( $item = readdir( $handle ) ) ) {
       if ( $item != "." && $item != ".." ) {
       if ( is_dir( "$dirName/$item" ) ) {
             delFileUnderDir( "$dirName/$item" );
       } else {
       if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />n";
       }
       }
       }
       closedir( $handle );
    }
    }
  • 相关阅读:
    CAP分布式
    专职DBA-MySQL数据库开篇
    os.sep
    DocStrings
    Python如何获取脚本的参数
    LVM基础命令
    VoAndEntityTrans
    短信倒计时
    springboot在eclipse上搭建项目一(无页面)
    springboot问题
  • 原文地址:https://www.cnblogs.com/myhomepages/p/5992621.html
Copyright © 2011-2022 走看看