上傳文件:
/** * 上傳文件 * @param string $file 文件路徑 */ function FileUpload($file){ $data = array('file'=>'文件路徑'); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "訪問的遠程服務器文件.php"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); $result = curl_exec($curl); curl_close($curl); /*釋放*/ }
解壓zip
/**
* 解壓文件夾
* @param string $filename 文件夾
* @param string $path 要上傳的路徑
*/ function get_zip_originalsize($filename, $path) { //先判斷待解壓的文件是否存在 if(!file_exists($filename)){ die("文件 $filename 不存在!"); } $starttime = explode(' ',microtime()); //解壓開始的時間 //將文件名和路徑轉成windows系統默認的gb2312編碼,否則將會讀取不到 $filename = iconv("utf-8","gb2312",$filename); $path = iconv("utf-8","gb2312",$path); //打開壓縮包 $resource = zip_open($filename); $i = 1; //遍歷讀取壓縮包里面的一個個文件 while ($dir_resource = zip_read($resource)) { //如果能打開則繼續 if (zip_entry_open($resource,$dir_resource)) { //獲取當前項目的名稱,即壓縮包里面當前對應的文件名 $file_name = $path.zip_entry_name($dir_resource); //以最后一個“/”分割,再用字符串截取出路徑部分 $file_path = substr($file_name,0,strrpos($file_name, "/")); //如果路徑不存在,則創建一個目錄,true表示可以創建多級目錄 if(!is_dir($file_path)){ mkdir($file_path,0777,true); } //如果不是目錄,則寫入文件 if(!is_dir($file_name)){ //讀取這個文件 $file_size = zip_entry_filesize($dir_resource); //最大讀取6M,如果文件過大,跳過解壓,繼續下一個 if($file_size<(1024*1024*30)){ $file_content = zip_entry_read($dir_resource,$file_size); file_put_contents($file_name,$file_content); }else{ echo "<p> ".$i++." 此文件已被跳過,原因:文件過大, -> ".iconv("gb2312","utf-8",$file_name)." </p>"; } } //關閉當前 zip_entry_close($dir_resource); } } //關閉壓縮包 zip_close($resource); $endtime = explode(' ',microtime()); //解壓結束的時間 $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]); $thistime = round($thistime,3); //保留3為小數 // echo "<p>解壓完畢!,本次解壓花費:$thistime 秒。</p>"; return true; }
以上就是這次的全部內容!