/** * Updates file in cashe. Even if it already in it. * @param $fileitentifier */ public static function updateFileInCache($fileitentifier) { $path = FileModification::createDirectory('filecache'); $path = FileModification::createDirectory('filecache/'.Yii::app()->user->clientID); if (is_file($fileitentifier)) { //if this if image from filesystem //convert to pdf $result_file_array = FileModification::PdfByFilePath($fileitentifier); $filepath = $result_file_array['filepath']; $filename = $result_file_array['filename']; $path_to_base = $filepath; $fileId = sha1_file($filepath).sha1($filepath); } else { //if this is image from database $image = Images::model()->findByAttributes(array( 'Document_ID' => intval($fileitentifier) )); if($image) { $mime = explode('/', $image->Mime_Type); $temp_file_path = $path . '/' . $image->File_Name; $infile = stripslashes($image->Img); file_put_contents($temp_file_path, $infile); $fileId = intval($fileitentifier); $path_to_base = $temp_file_path; } } FileCache::deleteFromCacheById($fileitentifier); FileCache::deleteFromCacheById($fileId); $fileCash = new FileCache(); $fileCash->file_id = $fileId; $fileCash->path = $path_to_base; $fileCash->client_id = Yii::app()->user->clientID; $fileCash->user_id = Yii::app()->user->userID; $fileCash->Created = time(); $fileCash->save(); $result_id = $fileCash->file_id; return $result_id; }