コード例 #1
0
 function get_file($f3)
 {
     $hash_id = $f3->get("PARAMS.hash_id");
     $id = Base56::decode($hash_id);
     $file = PFH_File_model::get($id);
     $filename = $file->filename;
     $filetype = $file->filetype;
     $md5 = $file->md5;
     //$filepath = PFH_MD5::get_file_path($f3, $md5);
     //$filepath = PFH_ZIP::read($f3, $md5);
     //$filepath = PFH_MD5::get_file_path($f3, $md5);
     $filepath = PFH_Archive::read($f3, $md5, $filename);
     $action = "download";
     PFH_Log_model::create_log($f3, $file, $action);
     $force_download = FALSE;
     PFH_File_helper::download_contents($filepath, $filetype, $filename, $force_download);
 }
コード例 #2
0
 static function create_from_upload($f3, $upload_file, $md5 = NULL)
 {
     // 檔案名稱
     $filename = $upload_file['name'];
     // 檔案大小
     $filesize = $upload_file['size'];
     // 檔案類型
     $filetype = $upload_file['type'];
     // md5
     if (is_null($md5)) {
         $md5 = md5_file($upload_file["tmp_name"]);
         $same_md5 = R::findOne("file", "md5 = ? AND (filesize <> ? OR filetype <> ?)", [$md5, $filesize, $filetype]);
         if (is_null($same_md5) === FALSE) {
             $same_md5_id = $same_md5->id;
             $hash_id = Base56::encode($same_md5_id);
             $md5 = $md5 . $hash_id;
         }
     }
     // 搜尋看看有沒有這個bean
     $file = R::findOne("file", "md5 = ? AND filename = ? AND filesize = ? AND filetype = ?", [$md5, $filename, $filesize, $filetype]);
     if (is_null($file)) {
         $file = R::dispense("file");
         //$file->title="哈利波特";
         //$id = R::store($file);
         //$data = array();
         // 檔案名稱
         $file->filename = $filename;
         // 檔案大小
         $file->filesize = $filesize;
         // 檔案類型
         $file->filetype = $filetype;
         // md5
         $file->md5 = $md5;
         // 是否刪除
         $deleted = FALSE;
         //$data["deleted"] = $deleted;
         $file->deleted = $deleted;
         //$hash = Base56::encode(1000000);
         //$data["hash"] = $hash;
         $id = R::store($file);
         $file->id = $id;
         //$bean->id = 9;
         // 移動檔案
         self::move_uploaded_file($f3, $upload_file["tmp_name"], $md5, $upload_file['name']);
         // 變成壓縮檔案
         //PFH_ZIP::create($f3, $md5);
         PFH_Archive::create($f3, $md5, $upload_file['name']);
     }
     //if (is_null($file)) {
     // 記錄上傳的資料
     $action = "upload";
     PFH_Log_model::create_log($f3, $file, $action);
     //echo $file->id;
     return $file;
 }