protected function saveMetaData($file) { $ext = $this->getExtension($file['name']); $realName = $this->getNameWithoutExtension($file['name']); if ($ext && $realName) { FPM::m()->getDb()->createCommand()->insert(FPM::m()->tableName, array('extension' => $ext, 'real_name' => $realName)); $id = FPM::m()->getDb()->getLastInsertID(); FPM::m()->getDb()->createCommand()->insert(FPM::m()->relatedTableName, array('file_id' => $id, 'model_id' => $this->owner->getPrimaryKey(), 'model_class' => $this->owner->getClassName())); FPM::m()->getDb()->createCommand()->insert(XFiles::w()->xuploadTableName, array('fpm_id' => $id, 'size' => $file['size'], 'mime' => $file['mime'], 'file_key' => $file['key'])); return $id; } return null; }
protected function handleThumb() { if (($marker = $this->getQuery('marker')) && ($stateVar = $this->getQuery('stateVar'))) { if ($files = Yii::app()->user->getState($stateVar)) { $filePath = $files[$marker]['path']; } else { echo 'error'; return true; } } elseif ($fileID = $this->getQuery('fileID')) { $filePath = urldecode(FPM::getOriginalFilePathById($fileID)); } else { echo 'error'; return true; } if (is_file($filePath)) { $ext = mb_strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); if (!in_array($ext, $this->showThumbFileExtension)) { if ($ext == 'docx') { $ext = 'doc'; } $filePath = XFiles::w()->assetsDir . DIRECTORY_SEPARATOR . 'Free-file-icons' . DIRECTORY_SEPARATOR . '512px' . DIRECTORY_SEPARATOR . $ext . '.png'; } $thumbParams = $this->getThumbParams(); $ih = Yii::createComponent(FPM::m()->imageHandler); $ih->init(); $ih->load($filePath); if (isset($thumbParams['do'])) { switch ($thumbParams['do']) { case 'adaptiveResize': $ih->adaptiveThumb($thumbParams['width'], $thumbParams['height']); break; case 'resize': $ih->resize($thumbParams['width'], $thumbParams['height']); break; default: throw new CHttpException(400, 'Incorrect action'); break; } } else { $ih->adaptiveThumb($thumbParams['width'], $thumbParams['height']); } $ih->show(false, $thumbParams['quality']); } }
public static function getAllFileInfoList($modelID, $modelName, $key = null) { $bindKey = empty($key) ? array() : array('file_key = :file_key'); $paramKey = empty($key) ? array() : array(':file_key' => $key); return FPM::m()->getDb()->createCommand()->select()->from(XFiles::w()->xuploadViewName)->where(CMap::mergeArray(array('and', 'model_id = :mid', 'model_class = :mclass'), $bindKey), CMap::mergeArray(array(':mid' => $modelID, ':mclass' => $modelName), $paramKey))->queryAll(); }