• 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 );
    }
    }
  • 相关阅读:
    swift基本数据类型的使用
    宏定义单例类
    开发必备宏定义大全
    GUI02
    GUI01
    浅谈代码块的加载顺序
    Java里的多态
    在java中this和super的使用
    冒泡排序的简单优化
    命令行传参和不定传参
  • 原文地址:https://www.cnblogs.com/myhomepages/p/5992621.html
Copyright © 2020-2023  润新知