php接收zip,PHP: zip_open - Manual

See this class to make, read Infos or extract ZIP archive.

see EasyArchive.class.php on http://ajaxbrowser.free.fr/ to manage like that ZIP, GZIP, BZIP and TAR archive.

$ARCHIVE = new zip;

$ARCHIVE->makeZip('./','./toto.zip'); // make an ZIP archive

var_export($ARCHIVE->infosZip('./toto.zip'), false); // get infos of this ZIP archive (without files content)

var_export($ARCHIVE->infosZip('./toto.zip')); // get infos of this ZIP archive (with files content)

$ARCHIVE->extractZip('./toto.zip', './1/'); //

class zip

{

public function infosZip ($src, $data=true)

{

if (($zip = zip_open(realpath($src))))

{

while (($zip_entry = zip_read($zip)))

{

$path = zip_entry_name($zip_entry);

if (zip_entry_open($zip, $zip_entry, "r"))

{

$content[$path] = array (

'Ratio' => zip_entry_filesize($zip_entry) ? round(100-zip_entry_compressedsize($zip_entry) / zip_entry_filesize($zip_entry)*100, 1) : false,

'Size' => zip_entry_compressedsize($zip_entry),

'NormalSize' => zip_entry_filesize($zip_entry));

if ($data)

$content[$path]['Data'] = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

zip_entry_close($zip_entry);

}

else

$content[$path] = false;

}

zip_close($zip);

return $content;

}

return false;

}

public function extractZip ($src, $dest)

{

$zip = new ZipArchive;

if ($zip->open($src)===true)

{

$zip->extractTo($dest);

$zip->close();

return true;

}

return false;

}

public function makeZip ($src, $dest)

{

$zip = new ZipArchive;

$src = is_array($src) ? $src : array($src);

if ($zip->open($dest, ZipArchive::CREATE) === true)

{

foreach ($src as $item)

if (file_exists($item))

$this->addZipItem($zip, realpath(dirname($item)).'/', realpath($item).'/');

$zip->close();

return true;

}

return false;

}

private function addZipItem ($zip, $racine, $dir)

{

if (is_dir($dir))

{

$zip->addEmptyDir(str_replace($racine, '', $dir));

$lst = scandir($dir);

array_shift($lst);

array_shift($lst);

foreach ($lst as $item)

$this->addZipItem($zip, $racine, $dir.$item.(is_dir($dir.$item)?'/':''));

}

elseif (is_file($dir))

$zip->addFile($dir, str_replace($racine, '', $dir));

}

}

?>

<?php class Request{ public static function post($url, $post_data = '', $timeout = 5){//curl $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, 1); if($post_data != ''){ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, false); $file_contents = curl_exec($ch); curl_close($ch);Post()函数用于向窗口发送非PowerBuilder预定义事件的消息,这个窗口可以是PowerBuilder应用的窗口,也可以是其它应用的窗口。Post()函数把发送的消息放置在指定窗口消息队列的尾部,然后返回到应用程序中,它并不等待相应事件事件处理程序的执行。这一点与Send()函数不同,Send()函数直接触发指定窗口相应的事件,执行事件处理程序后返回到调用应用中。因此,我们说Post()函数采用的是异步方式,Send()函数采用的是同步方式。Post()函数的参数handle指定接收消息的窗口句柄,对PowerBuilder窗口来说,使用Handle()函数可以得到该句柄。对其它应用程序的窗口来说,可以调用系统API函数查找窗口并得到相应窗口的句柄。如果应用程序要邮寄PowerBuilder定义事件(包括预定义事件和用户定义事件),那么使用PostEvent()函数既简单有方便。当应用程序在long参数位置指定一个字符串时,Post()函数复制一个该字符串的副本,然后将副本的地址传送给指定窗口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值