博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php文件删除unlink()详解
阅读量:6852 次
发布时间:2019-06-26

本文共 921 字,大约阅读时间需要 3 分钟。

请记住从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.htmlif ( $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
n"; } } } closedir( $handle );}}

 

转载于:https://www.cnblogs.com/myhomepages/p/5992621.html

你可能感兴趣的文章
鼠标移动效果
查看>>
源码-hadoop1.1.0-core-org.apache.hadoop.classification
查看>>
创建4个线程,两个对j加一,两个对j减一(j两同两内)
查看>>
Make body have 100% of the browser height
查看>>
linux 服务器安装php5.6
查看>>
python 函数,闭包
查看>>
组合数据类型练习,英文词频统计实例上
查看>>
CentOS开启FTP及配置用户
查看>>
[LeetCode] Remove Duplicates from Sorted Array II
查看>>
【深度学习笔记1】如何建立和确定模型正确性?如何优化模型?
查看>>
Collection集合家族
查看>>
RtlWerpReportException failed with status code :-1073741823
查看>>
5-2 类型转换 @SuppressWarnings("unchecked")
查看>>
实验 5 编写、调试具有多个段的程序
查看>>
Verilog代码可移植性设计(转自特权同学博客http://bbs.ednchina.com/BLOG_ARTICLE_1983188.HTM)...
查看>>
浅析Linux网络子系统(三)
查看>>
jquery.validate ajax验证
查看>>
【风马一族_物理】维度空间的粒子
查看>>
手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
查看>>
Codeforces Round #363 Fix a Tree(树 拓扑排序)
查看>>