寫到目的位置
$fp = fopen($this->targetPaths[$key],''w+'');
echo ''=>寫入目的檔..........'';
fwrite($fp,$fileAterZip);
fclose($fp);
echo ''完畢''.$this->newline;
//是否若選擇進行加密
if($this->bcompiler && $pathInfo[''extension''] == ''php''){
echo ''=>加密原始檔..........'';
//複製原始檔
$fh = fopen($this->targetPaths[$key].''encrypt.php'', "w");
bcompiler_write_header($fh);
bcompiler_write_file($fh, $this->targetPaths[$key]);
bcompiler_write_footer($fh);
fclose($fh);
//刪除未加密的原始檔
unlink($this->targetPaths[$key]);
//重新命名加密過後的檔案
rename($this->targetPaths[$key].''encrypt.php'',$this->targetPaths[$key]);
echo ''完畢''.$this->newline;
}
echo $this->newline.$this->newline;
}
}
//重新計算壓縮加密後的資料夾大小
$this->sizeAfterZip = $this->getSizeUnit($this->getDirSize($this->targetDir),2);
echo ''【結束加密
程序】''.$this->newline.$this->newline;
echo ''《報告資訊》''.$this->newline;
echo ''來源資料夾:''.$this->sourceDir.''(''.$this->sizeBeforeZip.'')''.$this->newline;
echo ''目的資料夾:''.$this->targetDir.''(''.$this->sizeAfterZip.'')''.$this->newline;
echo ''檔案大小增幅:+''.$this->getSizeUnit(($this->getDirSize($this->targetDir) - $this->getDirSize($this->sourceDir))).$this->newline;
echo ''檔案總數:''.count($this->sourcefilePaths).''個''.$this->newline;
}
/**
* 刪除目錄夾所有檔案
*
* @param string $dir 欲刪除的資料夾
* @param boolean $deleteSelf 同時刪除資料夾
* @return void
*/
private function cleanDir($dir=''.'',$deleteSelf=true){
if(!$dh = @opendir($dir)) return;
while (($obj = readdir($dh))) {
if($obj==''.'' || $obj==''..'') continue;
if (!@unlink($dir.''/''.$obj)) $this->cleanDir($dir.''/''.$obj, true);
}
if ($deleteSelf){
closedir($dh);
@rmdir($dir);
}
}
/**
* 取得資料夾的總檔案大小
*
* @param string $dir 欲剖析的資料夾
* @return int 位元組
*/
private function getDirSize($dir=''.''){
//取得檔案路徑清單
$filePaths = $this->getPaths($dir,''*'');
//初始化計數器
$sizeCounter = 0;
foreach($filePaths as $key => $path){
$sizeCounter = $sizeCounter + filesize($path);
}
return ($sizeCounter);
}
/**
* 取得資料夾所有配對的路徑
*
* @param string $start_dir 欲剖析的資料夾
* @return array 檔案路徑陣列
*/
private function getPaths($sDir, $sPattern, $nFlags = NULL){
$sDir = escapeshellcmd($sDir);
$aFiles = glob("$sDir/$sPattern", $nFlags);
foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir) {
$aSubFiles = $this->getPaths($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}
return $aFiles;
}
/**
* 檔案大小單位轉換函式
*
* @param int 檔案大小
* @param int 小數點位數
* @param boolean 是否要將資料切成陣列
* @return mix 字串或陣列
*/
public function getSizeUnit($size,$decimal=2,$split=false){
//設定單位序列
$unit = array(''Bytes'',''KB'',''MB'',''GB'',''TB'',''PB'',''EB'',''ZB'',''YB'');
//初始化索引
$flag = 0;
//進行簡化除算
while($size >= 1024){
$size = $size / 1024;
$flag++;
}
//是否要將數值與單位分開