设为首页 加入收藏

TOP

php文件删除unlink()详解
2017-10-10 12:00:46 】 浏览:4208
Tags: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 );
}
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP过滤HTML标签的三种方法 下一篇PHP 文件读取 fread、fgets、fget..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目