如何使用php删除zip文件 [英] How to delete a zip file using php
本文介绍了如何使用php删除zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我删除 zip 文件的 php 代码:
$name = "zip_file_name";chmod('./modules/',0777);unlink('./modules/'.$name.'.zip');
这里 modules
是包含的 zip 文件的文件夹.当我编写此代码时,出现错误:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"><h4>遇到 PHP 错误</h4><p>严重性:警告</p><p>消息:unlink(./modules/texts.zip) [<a href='function.unlink'>function.unlink</a>]:权限被拒绝</p><p>文件名:controllers/super_admin.php</p><p>行号:590</p>
如果我的代码有任何错误?
我也像这样检查chmod
:
chmod('./modules/'.$name.'.zip',0777);
但是我遇到了上面定义的相同错误.
解决方案
$name = "zip_file_name";$sPath = "./modules/" .$名称..压缩";$aFilePath =explode("/", $sPath);$i = 0;$sLastFolder = "";foreach ($aFilePath 作为 $sFolder) {$i++;if (file_exists($sLastFolder . $sFolder) || is_dir($sLastFolder . $sFolder)) {$this->make_writeable($sLastFolder . $sFolder);$iOldumask = umask(0);//重要部分 #1chmod($sLastFolder .$sFolder, 0777);umask($iOldumask);//重要部分#2$sLastFolder .= $sFolder ."/";}}取消链接($sPath);
This is my php code to delete a zip file:
$name = "zip_file_name";
chmod('./modules/',0777);
unlink('./modules/'.$name.'.zip');
Here modules
is the folder of zip file contained. When I wrote this code I got an error:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: unlink(./modules/texts.zip) [<a href='function.unlink'>function.unlink</a>]: Permission denied</p>
<p>Filename: controllers/super_admin.php</p>
<p>Line Number: 590</p>
</div>
If there is any mistake in my code?
I also check the chmod
like this:
chmod('./modules/'.$name.'.zip',0777);
But I got the same error define above.
解决方案
$name = "zip_file_name";
$sPath = "./modules/" . $name . ".zip";
$aFilePath = explode("/", $sPath);
$i = 0;
$sLastFolder = "";
foreach ($aFilePath as $sFolder) {
$i++;
if (file_exists($sLastFolder . $sFolder) || is_dir($sLastFolder . $sFolder)) {
$this->make_writeable($sLastFolder . $sFolder);
$iOldumask = umask(0); // important part #1
chmod($sLastFolder . $sFolder, 0777);
umask($iOldumask); // important part #2
$sLastFolder .= $sFolder . "/";
}
}
unlink($sPath);
这篇关于如何使用php删除zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文