Exemplo n.º 1
0
 protected function _bWriteFile($sFilename, $sExt, &$sDest)
 {
     if (false !== ($cl = curl_init('http://' . $this->_sDomain . '.oss-cn-beijing.aliyuncs.com/'))) {
         $sDest = str_replace('.', '_', uniqid('', true)) . '.' . trim($sExt, '.');
         $policy = array('expiration' => date('Y-m-d\\TH:i:s', time() + 86400) . '.000Z', 'conditions' => array(array('key' => $sDest)));
         $policy = base64_encode(json_encode($policy));
         $signature = base64_encode(hash_hmac('sha1', $policy, $this->_sSecretKey, 'true'));
         $postdata = array('OSSAccessKeyId' => $this->_sAccessKey, 'policy' => $policy, 'Signature' => $signature, 'key' => $sDest);
         if (class_exists('CURLFile')) {
             $postdata['file'] = new CURLFile($sFilename, Ko_Tool_Mime::sGetMimeType($sExt));
         } else {
             $postdata['file'] = '@' . $sFilename . ';type=' . Ko_Tool_Mime::sGetMimeType($sExt);
         }
         if (curl_setopt($cl, CURLOPT_RETURNTRANSFER, true) && curl_setopt($cl, CURLOPT_POSTFIELDS, $postdata)) {
             if (false !== ($ret = curl_exec($cl))) {
                 $code = curl_getinfo($cl, CURLINFO_HTTP_CODE);
                 if (200 <= $code && $code < 300) {
                     curl_close($cl);
                     return true;
                 }
             }
         }
         curl_close($cl);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * 设置Content-Type及Charset
  * @param string $sContentType content-type
  * @param string|null $sCharset 编码
  */
 public static function VSetContentType($sContentType, $sCharset = null)
 {
     static $s_aWhiteList = array('application/javascript', 'application/x-javascript', 'application/json', 'application/xml', 'application/rss+xml');
     $sContentType = ltrim(trim($sContentType), '.');
     $sContentType = false !== strpos($sContentType, '/') ? $sContentType : Ko_Tool_Mime::sGetMimeType($sContentType);
     if (null === $sCharset) {
         $sCharset = in_array($sContentType, $s_aWhiteList) || 'text/' === substr($sContentType, 0, 5) ? KO_CHARSET : '';
     }
     if ('' === $sCharset) {
         self::_VHeader('Content-Type', $sContentType);
     } else {
         self::_VHeader('Content-Type', $sContentType . '; charset=' . $sCharset);
     }
 }
Exemplo n.º 3
0
 protected function _bWriteFile($sFilename, $sExt, &$sDest)
 {
     if (false !== ($cl = curl_init('http://upload.qiniu.com/'))) {
         $postdata = array('token' => $this->_sGetUploadToken());
         if (class_exists('CURLFile')) {
             $postdata['file'] = new CURLFile($sFilename, Ko_Tool_Mime::sGetMimeType($sExt));
         } else {
             $postdata['file'] = '@' . $sFilename . ';type=' . Ko_Tool_Mime::sGetMimeType($sExt);
         }
         if (curl_setopt($cl, CURLOPT_RETURNTRANSFER, true) && curl_setopt($cl, CURLOPT_POSTFIELDS, $postdata)) {
             if (false !== ($ret = curl_exec($cl))) {
                 $arr = json_decode($ret, true);
                 if (is_array($arr) && isset($arr['key'])) {
                     $sDest = $arr['key'];
                     curl_close($cl);
                     return true;
                 }
             }
         }
         curl_close($cl);
     }
     return false;
 }