如何从目录中删除zip文件? [英] How do you delete a zip file from a directory?

查看:110
本文介绍了如何从目录中删除zip文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再一次,我认为我的类方法deleteZip()可以做到这一点,

但是它永远不会删除目录中的任何.zip *文件:


[PHP]

/ **

*删除此相册中的所有潜在ZIP文件。这种方法是由所有列表类继承
以允许

*列表范围内删除潜在服务器创建的ZIP文件以保证安全

用途

*

* @access私人

* @see actual_path

* @see is_class

* /

function& deleteZip(){// STATIC VOID METHOD

global $ section,$ {$ section。 ''LocationPath''},$ projectFullName;

$ album = $ _REQUEST [''album''];

$ locationPath =($ album)? $ {$ section。 LocationPath} / $专辑" :

$ {$ section。 ''LocationPath''};

if(@!is_class($ this-> dbAP,''DBActionPerformer''))$ this-> dbAP =&新的

DBActionPerformer(); //本地实施,除非已经存在

if(!$ _ ENV [''windir'']){// UNIX VERSION

$ statMsg = exec(" stat \\ \\" .actual_path($ locationPath)。" / * .zip * \"

2>& 1"); //使用UNIX检查''stat''用于定位任何ZIP文件,请

删除如果至少找到一个

}否则{// WINDOWS VERSION

list($ lsKommand,$ lsRedirect)=

@array_values($ this-> dbAP-> getKommandOSArray(''ls''));

$ statMsg = exec(" $ lsKommand \"" .actual_path($ locationPath)。

" / * .zip * \" $ lsRedirect");

}

if(@!unlink(actual_path($ locationPath)。''/ *。zip *'')&&

!preg_match (''/没有这样的文件/我',$ statMsg)){// WEB服务器不能

删除ZIP文件

list($ removeKommand,$ removeRedirect)=

@array_values($ this-> dbAP-> getKommandOSArray(''rmdir-force''));

$ msg = exec(" $ removeKommand \\ \\" .actual_path($ locationPath)。

" / * .zip * \" $ removeRedirect"); //允许服务器本身

删除它们

if(preg_match(''/ ^ rm:/ i'',$ msg)||($ _ENV [ ''windir'']&& $ msg))

die(" $ projectFullName由于安全问题而关闭

可能会损坏\中的ZIP文件$ locationPath \,请联系

管理员< p>错误:$ msg");

}

}


[/ PHP]


这就是:


statMsg = stat:不能统计`/www/html/tools/app/images/doom/*.zip*'':

没有这样的文件或目录



um,对不起但是* * * * * * * * * * $ $ $ $ $ $ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / >
自动生成并且在我执行ls -l时确实存在通过命令行,

0644的权限。

这会有效,请不要,请帮助


比谢谢

phil

解决方案

部分,


{


部分。 LocationPath},

Once again, I thought my class method deleteZip() would do the trick,
but it never deletes any .zip* file found in a directory:

[PHP]
/**
* Delete any latent ZIP files found in this album. This method is to
be inherited by all listing classes to allow for
* list-wide deletion of latent server-created ZIP files for security
purposes
*
* @access private
* @see actual_path
* @see is_class
*/
function &deleteZip() { // STATIC VOID METHOD
global $section, ${$section . ''LocationPath''}, $projectFullName;
$album = $_REQUEST[''album''];
$locationPath = ($album) ? "${$section . ''LocationPath''}/$album" :
${$section . ''LocationPath''};
if (@!is_class($this->dbAP, ''DBActionPerformer'')) $this->dbAP =& new
DBActionPerformer(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
if (!$_ENV[''windir'']) { // UNIX VERSION
$statMsg = exec("stat \"" . actual_path($locationPath) . "/*.zip*\"
2>&1"); // USE UNIX CHECK ''stat'' FOR LOCATING ANY ZIP FILES, DO
DELETION IF AT LEAST 1 FOUND
} else { // WINDOWS VERSION
list($lsKommand, $lsRedirect) =
@array_values($this->dbAP->getKommandOSArray(''ls''));
$statMsg = exec("$lsKommand \"" . actual_path($locationPath) .
"/*.zip*\" $lsRedirect");
}
if (@!unlink(actual_path($locationPath) . ''/*.zip*'') &&
!preg_match(''/no such file/i'', $statMsg)) { // WEB SERVER CANNOT
DELETE ZIP FILES
list($removeKommand, $removeRedirect) =
@array_values($this->dbAP->getKommandOSArray(''rmdir-force''));
$msg = exec("$removeKommand \"" . actual_path($locationPath) .
"/*.zip*\" $removeRedirect"); // ALLOW FOR THE SERVER ITSELF TO
DELETE THEM
if (preg_match(''/^rm:/i'', $msg) || ($_ENV[''windir''] && $msg))
die("$projectFullName shut down due to security issue with
potentially damaging ZIP file in \"$locationPath\", please contact
administrator<p>Error: $msg");
}
}

[/PHP]

This is what happens:

statMsg = stat: cannot stat `/www/html/tools/app/images/doom/*.zip*'':
No such file or directory

um, sorry but there *IS* at lease 1 zip file in
/www/html/tools/app/images/doom called images_of_doom.zip that is
auto-generated and does exist when I do "ls -l" via command line,
permissions of 0644.

How do I delete it and any other ZIP file, plain and simple, I thought
this would work and it doesn''t, please help

thanx
phil

解决方案

section,


{


section . ''LocationPath''},


这篇关于如何从目录中删除zip文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆