/** * 上传视频 * * @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; }
/** * banner文件上传 * * @return bool */ public function banneruploadAction() { header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); $sFromURL = $this->getRequest()->getHttpReferer(); $oStorage = new File_Storage(); $mResult = $oStorage->isAllowedDomain($sFromURL); $iRetError = 0; if (true === $mResult) { $aFiles = $this->getUploadFiles(); $sIP = $this->getRequest()->getClientIP(); $sDomain = Util_Uri::getDomain($sFromURL); $aUpdFiles = array(); // 批量上传图片 @todo 待优化 foreach ($aFiles as $aFile) { list($iError, $mResult) = $oStorage->saveFile($aFile['name'], $aFile['tmp_name'], $aFile['error'], $aFile['size'], $sIP, $sDomain, Model_FileMeta::BID_BANNER); if ($iError == 0) { $iRetError = 0; $mResult['iError'] = $iError; $aUpdFiles[$aFile['key']] = $mResult; } else { $aUpdFiles[$aFile['key']] = array('iError' => $iError, 'sMsg' => $mResult); } } $mResult = $aUpdFiles; } else { $iRetError = 1; $mResult = array('sMsg' => 'The upload domain is forbidden.'); } $this->getResponse()->setHeader('Content-Type', 'application/json'); $aRet = array_merge(array('iError' => $iRetError), $mResult); $this->getResponse()->setBody(json_encode($aRet)); return false; }