標籤:os io 檔案 ar cti new ad on
//這個是有什麼作用來這忘了
fopen(‘php://output‘,‘w‘);
1.
//demo zip格式的壓縮檔上傳
function zqFileUpload($path,$proDir,$filename){
global $_configuration;// root_sys 得到項目的根目錄
$dirpath=rtrim($_configuration[‘root_sys‘],‘/‘).$proDir;//上傳的路徑
if(!file_exists($dirpath)){
mkdir($dirpath);
}
$dirname =$filename.‘_‘.time().mt_rand(100);//目錄的名稱
$dir=$dirpath."/".$dirname;//建立目錄 和 解壓到的目錄
$filepath=$dir.‘/‘.$filename;// 上傳的檔案名稱
if ( mkdir($dir,0777, true) ){
if (move_uploaded_file($path,$filepath)) {
$zip = new ZipArchive();
$rs=$zip->open($filepath);
if($rs !== TRUE){
//exit("解壓失敗!");
}
$zip->extractTo($dir);
$zip->close();
unlink($filepath);
return $proDir.‘/‘.$dirname;//相對於web的根路徑
}
}
return false;
}
2.遞迴刪除目錄以及目錄下的檔案
//刪除目錄 (目錄 和檔案)
function deleteDir($path){
$path=rtrim($path,‘/‘);
if(file_exists($path)){
$handle = opendir($path);
while( FALSE !== $file=readdir($handle) ){
if($file==‘.‘ || $file==‘..‘){
continue;
}
$pathFile=$path.‘/‘.$file;
if(is_dir($pathFile)){
deleteDir($pathFile);
}else{
unlink($pathFile);
}
}
closedir($handle);
rmdir($path);
}
}