Skip to content

Instantly share code, notes, and snippets.

@erasin
Created August 27, 2013 08:52
Show Gist options
  • Save erasin/6351240 to your computer and use it in GitHub Desktop.
Save erasin/6351240 to your computer and use it in GitHub Desktop.
php 打包上传
<?php
// 打包
$zipfile = 'zipByPhp.zip';
$zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
if($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE){
exit('create zip file error');
}
$files = array('queryimg.php', 'multicurl.php');
foreach($files as $file){
$addfilename = iconv('UTF-8', 'GBK//IGNORE', $file);
$zip->addFile($file, $addfilename);
}
$zip->close();
// 上传
$field = array("upimg"=>"@/tmp/phpzip.zip");//文件路径,前面要加@,表明是文件上传.key与后台处理文件对应,使用$_FILES['upimg']获取
$curl = curl_init("http://localhost/a.php");
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$field);//这里的$field必须是数组结构,不要自作聪明使用 http_build_query,否则不认文件了
curl_exec($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment