Example #1
0
 /**
  * @biref       将网络文件上传到CDN源,非UTF-8的文本页面可能会出现乱码
  * @param       string  $url        网络文件的url
  * @param       int     $id         标识用户id,默认0
  * @param       string  $ext        文件的扩展名,$ext = 'jpg',如果不指定的话,会从url的扩展名中获取
  * @return      string  cdnKey      cdnKey
  * @exception   Exception
  */
 public static function uploadRemoteFile($url, $id = 0, $ext = '')
 {
     // 获取扩展名
     $path = Url::getPath($url);
     if (empty($ext) && strpos($path, '.')) {
         $arr = explode('.', $path);
         $ext = end($arr);
     }
     $ossClient = self::getOssClient();
     $cdnKey = self::makeKey($id, $ext);
     // 获取content type
     $contentType = '';
     if (!empty($ext)) {
         $mimeTypes = Response::getMimeTypes();
         $contentType = $mimeTypes[$ext];
     }
     $curl = new Curl();
     $ossClient->putObject(array('Bucket' => CdnConfig::BUCKET_NAME, 'Key' => $cdnKey, 'Content' => $curl->get($url), 'ContentEncoding' => GlobalConfig::CONTENT_CHARSET, 'ContentType' => $contentType));
     return $cdnKey;
 }
Example #2
0
 /**
  * @return null|string
  */
 public function getAcceptHeader()
 {
     $accept = explode(',', $_SERVER['HTTP_ACCEPT']);
     $type = null;
     if (isset($accept[0])) {
         $response = new Response();
         $mimeTypes = $response->getMimeTypes();
         $type = array_search($accept[0], $mimeTypes);
         if (false === $type) {
             $type = null;
         }
     }
     return $type;
 }