예제 #1
0
파일: Ueditor.php 프로젝트: pancke/yyaf
 /**
  * 上传视频
  *
  * @param
  *            $aConfig
  * @return array
  */
 public function uploadimg($aConfig)
 {
     $aReturn = array('state' => 'SUCCESS', 'url' => '', 'title' => '', 'original' => '', 'type' => '', 'size' => '');
     do {
         $sFileField = $aConfig['imageFieldName'];
         if (!isset($_FILES[$sFileField])) {
             $aReturn['state'] = '上传文件为空';
             break;
         }
         $sFromURL = $this->getRequest()->getHttpReferer();
         $oStorage = new File_Storage();
         $mResult = $oStorage->isAllowedDomain($sFromURL);
         if (!$mResult) {
             // 当前站点不允许上传到图片服务器
             $aReturn['state'] = '当前站点不允许上传到服务器';
             break;
         }
         $sIP = $this->getRequest()->getClientIP();
         $sDomain = Util_Uri::getDomain($sFromURL);
         $aFile = $_FILES[$sFileField];
         list($iError, $mResult) = $oStorage->saveFile($aFile['name'], $aFile['tmp_name'], $aFile['error'], $aFile['size'], $sIP, $sDomain);
         if ($iError !== 0) {
             $aReturn['state'] = $mResult;
             break;
         }
         $sCDNDomain = Yaf_G::getConf('file', 'domain');
         $aReturn['url'] = 'http://' . $sCDNDomain . '/view/' . $mResult['sKey'] . '.' . $mResult['sExt'];
         $aReturn['title'] = basename($aFile['name']);
         $aReturn['original'] = basename($aFile['name']);
         $aReturn['type'] = $mResult['sExt'];
         $aReturn['size'] = $mResult['iSize'];
     } while (false);
     return $aReturn;
 }
예제 #2
0
파일: File.php 프로젝트: pancke/yyaf
 public function moveAction()
 {
     $oStorage = new File_Storage();
     $sHost = $this->getParam('host');
     $iCnt = Model_File::query('SELECT COUNT(*) FROM t_file', 'one');
     for ($i = 0; $i < $iCnt; $i += 200) {
         $aList = Model_File::query("SELECT * FROM t_file LIMIT {$i},200");
         foreach ($aList as $aRow) {
             $sFileKey = $aRow['sKey'] . '.' . $aRow['sExt'];
             $sUrl = $sHost . '/view/' . $sFileKey;
             $sContent = file_get_contents($sUrl);
             $sDestFile = $oStorage->directSaveFile($aRow['sKey'], $sContent);
             echo "{$sUrl} => {$sDestFile}\n";
         }
     }
 }
예제 #3
0
파일: Index.php 프로젝트: pancke/yyaf
 /**
  * @return bool|void
  * 文件下载逻辑
  */
 public function downloadAction()
 {
     $params = $this->getParams();
     if (isset($params['key'])) {
         $sKey = $params['key'];
         $iWidth = 0;
         $iHeight = 0;
         if (isset($params['w']) && isset($params['h'])) {
             $iWidth = $params['w'];
             $iHeight = $params['h'];
         }
         if (isset($params['p'])) {
             $iWaterMarkPosition = intval($params['p']);
         }
         if (isset($params['m'])) {
             $iWaterMarkPath = intval($params['m']);
         }
         $sExt = $params['ext'];
         $bCrop = isset($params['crop']) && "c" == $params['crop'] ? true : false;
         $aFileInfo = '';
         $sDomain = $this->getRequest()->getHttpHost();
         $bllFile = new File_Storage();
         $iBid = Model_FileMeta::BID_DEFAULT;
         if (isset($params['biz']) && 'banner' == $params['biz']) {
             $iBid = Model_FileMeta::BID_BANNER;
         }
         $mRet = $bllFile->getFile($sKey, $sExt, $aFileInfo, $sDomain, $iWidth, $iHeight, $bCrop, $iWaterMarkPosition, $iWaterMarkPath, true, $iBid);
         if (true === $mRet) {
             if ($iWidth > 0 && $iHeight > 0) {
                 if (true == $bCrop) {
                     $aFileInfo['sName'] = $sKey . '_' . $iWidth . 'x' . $iHeight . '_' . $params['crop'];
                 } else {
                     $aFileInfo['sName'] = $sKey . '_' . $iWidth . 'x' . $iHeight;
                 }
             }
             return $this->sendDownloadFile($sKey, $aFileInfo);
         }
         if (in_array($mRet, [File_Storage::FILE_NOT_EXISTS, File_Storage::FILE_EXT_INVAILD, File_Storage::FILE_MIMETYPE_NOT_ALLOWED])) {
             return $this->sendNotFound();
         }
         if ($mRet === File_Storage::FILE_IMAGE_DIMENSION_NOT_ALLOWED) {
             return $this->sendUnauthorized();
         }
     } else {
         return $this->sendNotFound();
     }
 }