public static function read($f3, $md5, $filename) { $path_temp = PFH_MD5::get_tmp_file_path($f3, $md5, $filename); // 移除多餘的快取資料 PFH_Archive_cache::clean($f3, $path_temp); if (is_file($path_temp) === FALSE) { $path = PFH_MD5::get_file_path($f3, $md5, $filename); $tmp_dir = PFH_MD5::get_tmp_dir_path($f3, $md5); //$tmp_file = PFH_MD5::get_tmp_file_path($f3, $md5); if (is_file($path)) { // 沒有壓縮的情況 return $path; } //if (is_file($path)) { if (is_file($path . ".zip")) { $archive = new ZipArchive(); //echo $path; $res = $archive->open($path . ".zip"); //$zip->extractTo($tmp_file); $archive->extractTo($tmp_dir); $archive->close(); } else { if (is_file($path . ".bz2")) { $in_file = bzopen($path . ".bz2", "r"); $out_file = fopen($path_temp, "w"); while ($buffer = bzread($in_file, 4096)) { fwrite($out_file, $buffer, 4096); } bzclose($in_file); fclose($out_file); } } } // 加入快取資料 PFH_Archive_cache::add($f3, $path_temp); return $path_temp; }
/** * 移動檔案 * * @param Object $f3 * @param String $from_filepath 來源檔案 * @param String $md5 */ private static function move_uploaded_file($f3, $from_filepath, $md5, $filename) { $target_file_path = PFH_MD5::get_file_path($f3, $md5, $filename); if (is_file($target_file_path) === FALSE) { move_uploaded_file($from_filepath, $target_file_path); if (is_file($target_file_path) === FALSE) { rename($from_filepath, $target_file_path); } } if (is_file($from_filepath)) { unlink($from_filepath); } }