经常出现这种窘境,在公司上传东西的时候,需要传个easyui目录..再加个yiiframework哩。而且服务器没有linux的操作权限,zip的扩展也是没有的时候…如果以上都不是问题就跳出去吧呵呵。
http://www.phpconcept.net/pclzip/user-guide/18
这时肯定要将代码压缩下,传压缩包再通过代码去解压。
//普通的打包操作
$path = dirname ( __FILE__ ) . '/fw.zip';//目标zip
require_once (dirname ( __FILE__ ) . '/pclzip.lib.php');
$archive = new PclZip ( $path );
$archive->create ( "fw" );//当前需要打包的目录
if ($archive->extract () == 0) {
die ( "Error : " . $archive->errorInfo ( true ) );
}
//打包指定目录,然后移除目录前缀
$path = dirname ( __FILE__ ) . '/fw.zip';
require_once (dirname ( __FILE__ ) . '/pclzip.lib.php');
$archive = new PclZip ( $path );
$archive->add ( "C:/ooxx/ooxx/htdocs/test/zip/fw", PCLZIP_OPT_REMOVE_PATH, "/ooxx/ooxx/htdocs/test/zip/" ); // 压缩);
if ($archive->extract () == 0) {
die ( "Error : " . $archive->errorInfo ( true ) );
}
//普通的解包
$path = dirname ( __FILE__ ) . '/fw.zip';
require_once (dirname ( __FILE__ ) . '/pclzip.lib.php');
$archive = new PclZip ( $path );
if ($archive->extract () == 0) {
die ( "Error : " . $archive->errorInfo ( true ) );
}
看一送一,因为解压后的特殊原因,权限是只有应用的,如果ftp操作肯定是不行滴
//迭代授权,这样就绝配了。
function chmod_R($path, $filemode) {
if (! is_dir ( $path ))
return chmod ( $path, $filemode );
$dh = opendir ( $path );
while ( $file = readdir ( $dh ) ) {
if ($file != '.' && $file != '..') {
$fullpath = $path . '/' . $file;
if (! is_dir ( $fullpath )) {
if (! chmod ( $fullpath, $filemode ))
return FALSE;
} else {
if (! chmod_R ( $fullpath, $filemode ))
return FALSE;
}
// echo $fullpath."<br>";
}
}
closedir ( $dh );
if (chmod ( $path, $filemode ))
return TRUE;
else
return FALSE;
}
//用户和用户组的设置
function recurse_chown_chgrp($mypath, $uid, $gid) {
$d = opendir ( $mypath );
while ( ($file = readdir ( $d )) !== false ) {
if ($file != "." && $file != "..") {
$typepath = $mypath . "/" . $file;
// print $typepath. " : " . filetype ($typepath). "<BR>" ;
if (filetype ( $typepath ) == 'dir') {
recurse_chown_chgrp ( $typepath, $uid, $gid );
}
chown ( $typepath, $uid );
chgrp ( $typepath, $gid );
}
}
}
转发请注明出处http://blog.martoo.cn
如有漏缺,请联系我 QQ 243008827