Home > php教程 > php手册 > body text

三种php删除文件代码

WBOY
Release: 2016-06-13 11:24:48
Original
2272 people have browsed it

下面我收藏了三php删除文件哦,他可以利用unlink删除任何可删除的文件,本程序要删除文件,图片,压缩文件等,我们利用了几种方法来实例

下面我收藏了三php教程删除文件哦,他可以利用unlink删除任何可删除的文件,本程序要删除文件,图片,压缩文件等,我们利用了几种方法来实例。

三种php删除文件代码

if($od=opendir($d))   //$d是目录名
{
        while(($file=readdir($od))!==false)  //www.zhutiai.com 读取目录内文件
        {
        unlink($file);  //$file是文件名
        }
}

去了解下这三个php函数:opendir()  readdir()  unlink()

文件删除代码二 系统调用法

 

function del_dir($dir)
{
if(strtoupper(substr(php_os, 0, 3)) == 'win') {
       $str = "rmdir /s/q " . $dir;
} else {
       $str = "rm -rf " . $dir;
}
}

文件删除代码三

$info = "a123"; //目录名
if(is_dir($info)){
if(rmdir($info)){
echo "目录{$inof}删除完毕www.bkjia.com";
}else{
echo "目录无法删除!原因--可能是目录下还存在文件!";
}
}
if(is_file($info)){
if(unlink($info)){
echo "文件{$info}删除完毕...!";
}else{
echo "文件{$info}mb.php100.com删除失败...!尝试修改文件权限删除...";
if(chmod($info,0777)){
unlink($info);
echo "文件{$info}权限修改后删除完毕...";
}else{
echo "文件{$info}无法通过web方式删除,可能是ftp权限对此文件有所设置...";
}
}
}

最近发现很多网站转载本站文件,注请加上本站连接,谢谢合作!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!