Ejemplo n.º 1
0
/**
 * Created by PhpStorm.
 * User: xingminglister
 * Date: 4/18/14
 * Time: 3:50 PM
 */
function upload_to_qiniu($filepath)
{
    require_once "qiniu/io.php";
    require_once "qiniu/rs.php";
    $bucket = "hitour";
    $qiniu_link = '';
    $names = pathinfo($filepath);
    $qiniu_key = md5($filepath) . (empty($names['extension']) ? '' : '.' . $names['extension']);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    $upToken = $putPolicy->Token(null);
    $putExtra = new Qiniu_PutExtra();
    $putExtra->Crc32 = 1;
    list($ret, $err) = Qiniu_PutFile($upToken, $qiniu_key, $filepath, $putExtra);
    //	echo "[" . (date('Ymd H:i:s', time())) . "] ====> Qiniu_PutFile result: \n";
    if ($err !== null) {
        if ($err->Code == 614) {
            $qiniu_link = 'http://hitour.qiniudn.com/' . $qiniu_key;
        }
        //		echo $filepath . "\n";
        //		var_dump($err);
    } else {
        //		var_dump($ret);
        if (!empty($ret['key'])) {
            $qiniu_link = 'http://hitour.qiniudn.com/' . $ret['key'];
        }
    }
    return $qiniu_link;
}
Ejemplo n.º 2
0
 public function upload_qiniu($file = "", $name = "")
 {
     $path = $_SERVER['DOCUMENT_ROOT'];
     require_once $path . "/app/libraries/qiniu/rs.php";
     require_once $path . "/app/libraries/qiniu/io.php";
     $bucket = "meilimei";
     $local_file = "upload/" . $name;
     $key = $local_file;
     $accessKey = 'tjtiZoMyJa9ggnNisrdocCCGvTlNLFvYxGMMQ6LF';
     $secretKey = '6zQXHont_jN-QFznn96H4oKA7IUqjibPeC-Yto62';
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     if (move_uploaded_file($file, $local_file)) {
         $upload_file = $path . "/upload/" . $name;
         $putExtra = new Qiniu_PutExtra();
         $putExtra->Crc32 = 1;
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $upload_file, $putExtra);
         if ($err !== null) {
             return false;
         } else {
             //var_dump($ret);
             return $ret;
         }
     } else {
         return false;
         // 			echo "move_uploaded错误!";
         // 			die;
     }
     return false;
 }
Ejemplo n.º 3
0
 public function saveFile($token, $filename, $file, $ext = null)
 {
     list($ret, $err) = Qiniu_PutFile($token, $filename, $file, $ext);
     if (!empty($err)) {
         throw new Exception(print_r($err, 1));
     }
     return $ret;
 }
Ejemplo n.º 4
0
 public function upload($key, $source)
 {
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     return Qiniu_PutFile($upToken, $key, $source, $putExtra);
 }
Ejemplo n.º 5
0
 public function uploadfile($file_path)
 {
     list($ret, $err) = Qiniu_PutFile($this->upToken, $file_path, @$_FILES['file']['tmp_name'], $this->putExtra);
     @($ret['key'] = $this->file_domain . @$ret['key']);
     //
     if ($err !== null) {
         return $err;
     } else {
         return $ret;
     }
 }
Ejemplo n.º 6
0
 public function upFile($filename, $filepath)
 {
     require_once LIBPATH . 'Qiniu/io.php';
     require_once LIBPATH . 'Qiniu/rs.php';
     $this->getUpToken();
     Qiniu_SetKeys($accessKey, $secretKey);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     $info = Qiniu_PutFile($this->upToken, $filename, $filepath, $putExtra);
     return array('info' => $info[0], 'error' => $info[1]);
 }
Ejemplo n.º 7
0
 public function upload($filename, $filepath)
 {
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     $filename = $this->newfilename($filename);
     list($ret, $err) = Qiniu_PutFile($this->uptoken(), $filename, $filepath, $putExtra);
     if ($err !== null) {
         return false;
     } else {
         return $ret;
     }
 }
Ejemplo n.º 8
0
 public function testStat()
 {
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket . ":" . $this->key);
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = Qiniu_PutFile($upToken, $this->key, __FILE__, null);
     $this->assertNull($err);
     Qiniu_RS_Delete($this->client, $this->bucket, $this->notExistKey);
     list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $this->key);
     $this->assertArrayHasKey('hash', $ret);
     $this->assertNull($err);
     list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $this->notExistKey);
     $this->assertNull($ret);
     $this->assertFalse($err === null);
 }
Ejemplo n.º 9
0
 public function write($filename, $filePath)
 {
     $this->setBucketAndKey($filename);
     Qiniu_SetKeys($this->accessKey, $this->secretKey);
     $putPolicy = new \Qiniu_RS_PutPolicy($this->bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new \Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $this->key, $filePath, $putExtra);
     if ($err !== null) {
         throw new RuntimeException('Qiniu::write Error. ' . 'TargetFilename: ' . $filename . ', LocalFile: ' . $filePath . ', Reqid: ' . $err->Reqid . ', Err: ' . $err->Err, $err->Code);
     } else {
         return $ret['hash'];
     }
 }
Ejemplo n.º 10
0
 /**
  * 上传文件
  * @param type $uploadFile 文本框上传文件名
  * @param type $qiniuFileName 存储在七牛里面的文件名
  */
 public function uploadFile($uploadFile, $qiniuFileName)
 {
     require_once 'qiniu/io.php';
     $file = $_FILES[$uploadFile]['tmp_name'];
     // 上传文件的位置
     $putPolicy = new Qiniu_RS_PutPolicy($this->_bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $qiniuFileName, $file, $putExtra);
     if ($err !== null) {
         return array('succ' => false, 'data' => $err);
     } else {
         //            picThumb($accessKey, $secretKey, $key1, $width=100, $height=100);
         return array('succ' => true, 'data' => $ret);
     }
 }
Ejemplo n.º 11
0
 public function testPutFile()
 {
     $key = 'testPutFile' . getTid();
     $err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->CheckCrc = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $key, __FILE__, $putExtra);
     $this->assertNull($err);
     $this->assertArrayHasKey('hash', $ret);
     var_dump($ret);
     list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
     $this->assertNull($err);
     var_dump($ret);
     $err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $this->assertNull($err);
 }
Ejemplo n.º 12
0
 public function testPutFileWithPersistentOps()
 {
     $key = 'testPutFileWithPersistentOps' . getTid();
     $err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
     $putPolicy->PersistentOps = 'avthumb/mp3';
     $putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->CheckCrc = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $key, __FILE__, $putExtra);
     $this->assertNull($err);
     $this->assertArrayHasKey('hash', $ret);
     $this->assertArrayHasKey('persistentId', $ret);
     var_dump($ret);
     list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
     $this->assertNull($err);
     var_dump($ret);
     $err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $this->assertNull($err);
 }
Ejemplo n.º 13
0
 /**
  * 文件上传
  * @param string $filePath 待上传文件的绝对路径
  * @return string 上传成功后的URL,失败时返回空
  */
 public function uploadFile($filePath)
 {
     $fileUrl = '';
     if (!file_exists($filePath)) {
         return $fileUrl;
     }
     $config = $this->config;
     $fileName = date('YmdHis_', $_SERVER['REQUEST_TIME']) . md5(PhalApi_Tool::createRandStr(8) . microtime(true));
     Qiniu_SetKeys($config['accessKey'], $config['secretKey']);
     $putPolicy = new Qiniu_RS_PutPolicy($config['space_bucket']);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $fileName, $filePath, $putExtra);
     if ($err !== null) {
         DI()->logger->debug('failed to upload file to qiniu', array('Err' => $err->Err, 'Reqid' => $err->Reqid, 'Details' => $err->Details, 'Code' => $err->Code));
     } else {
         $fileUrl = $config['space_host'] . '/' . $fileName;
         DI()->logger->debug('succeed to upload file to qiniu', $ret);
     }
     return $fileUrl;
 }
Ejemplo n.º 14
0
 /**
  * Upload file to qiniu cloud
  * @param  string $filePath file path
  * @param  string $key      file name in qiniu
  * @param  bool   $isAllowedOverwrite
  */
 public function upload($filePath, $key, $isAllowedOverwrite = false)
 {
     if ($isAllowedOverwrite) {
         $upToken = $this->getToken($key);
     } else {
         $upToken = $this->getToken();
     }
     if (filesize($filePath) > 1 << self::QINIU_UPLOAD_BLOCK_BITS) {
         LogUtil::info(['message' => 'upload file use block', 'filePath' => $filePath], 'resque');
         $putExtra = new \Qiniu_Rio_PutExtra();
         list($ret, $err) = Qiniu_Rio_PutFile($upToken, $key, $filePath, $putExtra);
     } else {
         LogUtil::info(['message' => 'upload file directly', 'filePath' => $filePath], 'resque');
         $putExtra = new \Qiniu_PutExtra();
         $putExtra->Crc32 = 1;
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $filePath, $putExtra);
     }
     if ($err !== null) {
         return $err;
     } else {
         return $ret;
     }
 }
 /**
  * $filename 七牛可以手动填写路径
  */
 function sendToQiniu($path, $filename)
 {
     Qiniu_setKeys(self::$qiniuAccessKey, self::$qiniuSecretKey);
     $qiniu = new Qiniu_MacHttpClient(null);
     $putPolicy = new Qiniu_RS_PutPolicy(self::$bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $filename, $path, $putExtra);
     if ($err) {
         return array('code' => -2, 'msg' => $err);
     } else {
         $file = $ret['key'];
         $domain = self::$bucket . '.qiniudn.com';
         $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $file);
         $private = false;
         if ($private) {
             $getPolicy = new Qiniu_RS_GetPolicy();
             $baseUrl = $getPolicy->MakeRequest($baseUrl, null);
         }
         return array('code' => 0, 'msg' => $baseUrl);
     }
 }
Ejemplo n.º 16
0
 /**
  * 上传文件到七牛
  * @param string $file 源文件  
  * @param string $upname 上传后的文件名  
  * @param string $bucket 七牛上传的位置 
  */
 public static function upFiletoQiniu($file, $upname, $bucket)
 {
     $path = Yii::getPathOfAlias('application');
     require_once $path . "/vendors/qiniu/rs.php";
     require_once $path . "/vendors/qiniu/io.php";
     $qiniu_config = Yii::app()->params['qiniuConfig'];
     $accessKey = $qiniu_config['ak'];
     $secretKey = $qiniu_config['sk'];
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     list($ret, $err) = Qiniu_PutFile($upToken, $upname, $file, $putExtra);
     if ($err !== null) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 17
0
/**
 * @param $tmp
 * @param $upload
 */
function CloudStorage($tmp, &$upload)
{
    global $zbp;
    $bucket = $zbp->Config('CloudStorage')->CS_Bucket;
    //云文件夹
    $filename = date("Ymd", time()) . mt_rand(1000, 9999) . '_' . mt_rand(0, 1000) . '.' . GetFileExt($upload->SourceName);
    $object = $zbp->Config('CloudStorage')->CS_Dir . date("Y/m/", time()) . $filename;
    //构造云文件名
    $file_path = $zbp->usersdir . 'upload/tmp.data';
    //本地临时文件地址
    @move_uploaded_file($tmp, $file_path);
    //先上传到本地
    $upload->Name = $filename;
    switch ($zbp->Config('CloudStorage')->CS_Storage) {
        case '1':
            define('OSS_ACCESS_ID', $zbp->Config('CloudStorage')->CS_Ali_KeyID);
            //ACCESS_ID
            define('OSS_ACCESS_KEY', $zbp->Config('CloudStorage')->CS_Ali_KeySecret);
            //ACCESS_KEY
            require_once dirname(__FILE__) . '/api/oss/sdk.class.php';
            $os_service = new ALIOSS();
            $os_service->set_debug_mode(FALSE);
            //$os_service->set_enable_domain_style(TRUE);//二级域名
            $response = $os_service->upload_file_by_file($bucket, $object, $file_path);
            //将本地文件上传到云
            $upload->Metas->CS_URL = $response->header['_info']['url'];
            break;
        case '2':
            require_once dirname(__FILE__) . '/api/qiniu/io.php';
            require_once dirname(__FILE__) . '/api/qiniu/rs.php';
            $accessKey = $zbp->Config('CloudStorage')->CS_QNiu_KeyID;
            $secretKey = $zbp->Config('CloudStorage')->CS_QNiu_KeySecret;
            Qiniu_SetKeys($accessKey, $secretKey);
            $putPolicy = new Qiniu_RS_PutPolicy($bucket);
            $upToken = $putPolicy->Token(null);
            //$putExtra = new Qiniu_PutExtra();
            //$putExtra->Crc32 = 1;
            list($ret, $err) = Qiniu_PutFile($upToken, $object, $file_path, null);
            $upload->Metas->CS_URL = 'http://' . $bucket . '.qiniudn.com/' . $ret['key'];
            //20140509更新V1.1:删除u
            break;
        case '3':
            define('BCS_AK', $zbp->Config('CloudStorage')->CS_Baidu_KeyID);
            //AK 公钥
            define('BCS_SK', $zbp->Config('CloudStorage')->CS_Baidu_KeySecret);
            //SK 私钥
            require_once dirname(__FILE__) . '/api/bcs/bcs.class.php';
            $baidu_bcs = new BaiduBCS();
            $object = "/" . $object;
            $response = $baidu_bcs->create_object($bucket, $object, $file_path, array('acl' => 'public-read'));
            //var_dump($response);die();
            $upload->Metas->CS_URL = "http://bcs.duapp.com/" . $bucket . $object;
            //$response->header['_info']['url'];
            //未解决文件标识
            break;
        default:
            break;
    }
    $upload->Metas->CS_Tpye = $zbp->Config('CloudStorage')->CS_Storage;
    unlink($file_path);
    //删除本地文件
    $GLOBALS['Filter_Plugin_Upload_SaveFile']['CloudStorage'] = PLUGIN_EXITSIGNAL_RETURN;
    return true;
}
Ejemplo n.º 18
0
 public static function uploadFile($file, $content = null)
 {
     // 获取上传文件
     if (empty($file['name'])) {
         return false;
     }
     // 校验扩展名
     $part = explode('.', $file['name']);
     $ext = ($length = count($part)) > 1 ? strtolower($part[$length - 1]) : '';
     if (!Widget_Upload::checkFileType($ext)) {
         return false;
     }
     // 获取插件配置
     $option = self::getConfig();
     $date = new Typecho_Date(Typecho_Widget::widget('Widget_Options')->gmtTime);
     // 保存位置
     $savepath = preg_replace(array('/\\{year\\}/', '/\\{month\\}/', '/\\{day\\}/'), array($date->year, $date->month, $date->day), $option->savepath);
     $savename = $savepath . sprintf('%u', crc32(uniqid())) . '.' . $ext;
     if (isset($content)) {
         $savename = $content['attachment']->path;
         self::deleteFile($savename);
     }
     // 上传文件
     $filename = $file['tmp_name'];
     if (!isset($filename)) {
         return false;
     }
     // 初始化 SDK
     self::initSDK($option->accesskey, $option->sercetkey);
     // 上传凭证
     $policy = new Qiniu_RS_PutPolicy($option->bucket);
     $token = $policy->Token(null);
     $extra = new Qiniu_PutExtra();
     $extra->Crc32 = 1;
     // 上传
     list($result, $error) = Qiniu_PutFile($token, $savename, $filename, $extra);
     if ($error == null) {
         return array('name' => $file['name'], 'path' => $savename, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($savename));
     } else {
         return false;
     }
 }
Ejemplo n.º 19
0
 function upload($source, $target)
 {
     if ($this->error()) {
         return 0;
     }
     switch ($this->curstorage) {
         case 'upyun':
             $fh = fopen($source, 'rb');
             $target = substr($target, 0, 1) == "/" ? $target : '/' . $target;
             $succeed = $this->curobj->writeFile($target, $fh, true);
             // 上传图片,自动创建目录
             fclose($fh);
             return $succeed;
         case 'aliyun':
             $return = $this->curobj->upload_file_by_file($this->config_ext['bucket'], substr($target, 0, 1) == "/" ? substr($target, 1) : $target, $source);
             return substr((string) $return->status, 0, 1) == 2 ? 1 : 0;
         case 'qiniu':
             $putPolicy = new Qiniu_RS_PutPolicy($this->config_ext['bucket']);
             $upToken = $putPolicy->Token(null);
             $putExtra = new Qiniu_PutExtra();
             $putExtra->Crc32 = 1;
             $target = substr($target, 0, 1) == '/' ? substr($target, 1) : (substr($target, 0, 2) == './' ? substr($target, 2) : $target);
             list($ret, $err) = Qiniu_PutFile($upToken, $target, $source, $putExtra);
             return $ret == null ? 0 : 1;
         case 'grand':
             return 0;
     }
     $old_dir = $this->ftp_pwd();
     $dirname = dirname($target);
     $filename = basename($target);
     if (!$this->ftp_chdir($dirname)) {
         if ($this->ftp_mkdir($dirname)) {
             $this->ftp_chmod($dirname);
             if (!$this->ftp_chdir($dirname)) {
                 $this->set_error(FTP_ERR_CHDIR);
             }
             $this->ftp_put('index.htm', getglobal('setting/attachdir') . '/index.htm', FTP_BINARY);
         } else {
             $this->set_error(FTP_ERR_MKDIR);
         }
     }
     $res = 0;
     if (!$this->error()) {
         if ($fp = @fopen($source, 'rb')) {
             $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
             @fclose($fp);
             !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
         } else {
             $this->set_error(FTP_ERR_SOURCE_READ);
         }
     }
     $this->ftp_chdir($old_dir);
     return $res ? 1 : 0;
 }
function apQiniu_RS_PutFile($self, $bucket, $key, $localFile, $putExtra)
{
    $dcqvimrpltf = "upToken";
    ${"GLOBALS"}["rgramtm"] = "key";
    $gdqsbapv = "putPolicy";
    ${$gdqsbapv} = new Qiniu_RS_PutPolicy_apf("{$bucket}:{$key}");
    ${"GLOBALS"}["lspqcbqhrs"] = "localFile";
    ${"GLOBALS"}["hjjkkvrhmtg"] = "putExtra";
    ${"GLOBALS"}["zxwfjlqye"] = "upToken";
    ${$dcqvimrpltf} = $putPolicy->Token($self->Mac);
    return Qiniu_PutFile(${${"GLOBALS"}["zxwfjlqye"]}, ${${"GLOBALS"}["rgramtm"]}, ${${"GLOBALS"}["lspqcbqhrs"]}, ${${"GLOBALS"}["hjjkkvrhmtg"]});
}
Ejemplo n.º 21
0
    include "appconfig.php";
    $arrType = array(".jpg", ".gif", ".bmp", ".jpeg", ".png");
    if (strstr($_FILES['file']['name'], ".jpg") or strstr($_FILES['file']['name'], ".gif") or strstr($_FILES['file']['name'], ".bmp") or strstr($_FILES['file']['name'], ".jpeg") or strstr($_FILES['file']['name'], ".png")) {
        date_default_timezone_set('PRC');
        $time = date('Y-m-d H:i:s');
        $nfilename = $time . "_" . rand(10000, 99999) . "_" . $_FILES["file"]["name"];
        require_once "qiniu/io.php";
        require_once "qiniu/rs.php";
        $key1 = $nfilename;
        //$_FILES["file"]["name"];
        Qiniu_SetKeys($accessKey, $secretKey);
        $putPolicy = new Qiniu_RS_PutPolicy($bucket);
        $upToken = $putPolicy->Token(null);
        $putExtra = new Qiniu_PutExtra();
        $putExtra->Crc32 = 1;
        list($ret, $err) = Qiniu_PutFile($upToken, $key1, $_FILES["file"]["tmp_name"], $putExtra);
        //echo "====> Qiniu_PutFile result: \n";
        if ($err !== null) {
            var_dump($err);
        } else {
            echo "http://" . $qiniuurl . "/" . $nfilename;
            //var_dump($ret);
            $mediaurl = "http://" . $qiniuurl . "/" . $nfilename;
            mysql_query("insert into lts_pic(picname,picurl) values(" . "'" . $nfilename . "','" . $mediaurl . "')");
            mysql_query("insert into lts_msg(pic,picname,msgtime,username) values(" . "true,'" . $nfilename . "','" . $time . "','" . htmlspecialchars($_COOKIE['ltsuser']) . "" . "')");
        }
    } else {
        echo "error";
    }
    mysql_close($link);
}
Ejemplo n.º 22
0
function Qiniu_RS_PutFile($self, $bucket, $key, $localFile, $putExtra)
{
    $putPolicy = new Qiniu_RS_PutPolicy("{$bucket}:{$key}");
    $upToken = $putPolicy->Token($self->Mac);
    return Qiniu_PutFile($upToken, $key, $localFile, $putExtra);
}
Ejemplo n.º 23
0
    $ftp->upload($localfile, $remotefile);
}
//上传到七牛云存储start
require_once dirname(__FILE__) . "/../qiniu/io.php";
require_once dirname(__FILE__) . "/../qiniu/rs.php";
$qiniupath = substr($activepath, 1);
$bucket = 'mcgmh-upload';
$qiniudomain = 'http://upload.mcgmh.com';
//七牛云存储域名请自行修改 by CMS资源网www.dedejs.com
$key = $qiniupath . "/" . $filename;
$client = new Qiniu_MacHttpClient(null);
$putPolicy = new Qiniu_RS_PutPolicy("{$bucket}:{$key}");
$upToken = $putPolicy->Token(null);
$putExtra = new Qiniu_PutExtra();
$s = time();
list($ret, $err) = Qiniu_PutFile($upToken, $key, $fullfilename, $putExtra);
//上传到七牛云存储end
if ($uploadfile_type == 'application/x-shockwave-flash') {
    $mediatype = 2;
} else {
    if (preg_match('#image#i', $uploadfile_type)) {
        $mediatype = 1;
    } else {
        if (preg_match('#audio|media|video#i', $uploadfile_type)) {
            $mediatype = 3;
        } else {
            $mediatype = 4;
        }
    }
}
$inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)\r\n   VALUES ('0','{$filename}','{$fullfileurl}','{$mediatype}','0','0','0','{$uploadfile_size}','{$nowtme}','" . $cuserLogin->getUserID() . "'); ";
Ejemplo n.º 24
0
 /* 上传文件 */
 case 'uploadfile':
     $result = (include "action_upload.php");
     $data = json_decode($result, TRUE);
     // 图片上传至七牛
     require_once $_SERVER['DOCUMENT_ROOT'] . "/qiniu/io.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/qiniu/rs.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/qiniu/config.php";
     $key1 = time() . $data['type'];
     Qiniu_SetKeys($accessKey, $secretKey);
     $putPolicy = new Qiniu_RS_PutPolicy($bucket);
     $upToken = $putPolicy->Token(null);
     $putExtra = new Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     $file = $_SERVER['DOCUMENT_ROOT'] . $data['url'];
     list($ret, $err) = Qiniu_PutFile($upToken, $key1, $file, $putExtra);
     if ($err !== null) {
         var_dump($err);
     } else {
         unlink($file);
         // 拼上域名返回
         $data['url'] = $IMG_DOMAIN . $ret['key'];
     }
     $result = json_encode($data);
     break;
     /* 列出图片 */
 /* 列出图片 */
 case 'listimage':
     $result = (include "action_list.php");
     break;
     /* 列出文件 */
Ejemplo n.º 25
0
function uploadQiNiu($filePath)
{
    //这里写入七牛的空间名
    $bucket = "1111";
    //$bucket = "gavinwen-topic";
    $name = basename($filePath);
    //这里写入七牛的accessKey和secretKey
    $accessKey = 'sVv4Xk-11';
    $secretKey = '333-11222';
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    $upToken = $putPolicy->Token(null);
    $putExtra = new Qiniu_PutExtra();
    $putExtra->Crc32 = 1;
    list($ret, $err) = Qiniu_PutFile($upToken, $name, $filePath, $putExtra);
    //list($ret, $err) = Qiniu_PutFile($upToken, $key1, __file__, $putExtra);
    //echo "====> Qiniu_PutFile result: \n";
    if ($err !== null) {
        return false;
        //print_r($err);
    } else {
        $attachmentUrl = "http://{$bucket}.qiniudn.com/{$name}";
        return $attachmentUrl;
    }
}
Ejemplo n.º 26
0
 public function putFileOrigin($filePath)
 {
     if (!file_exists($filePath)) {
         throw new FileNotFoundException($filePath, 404);
     }
     //        $key = md5_file( $filePath );
     $key = preg_replace('/(.*)\\/{1}([^\\/]*)/i', '$2', $filePath);
     $upToken = $this->getUpToken();
     $putExtra = new \Qiniu_PutExtra();
     $putExtra->Crc32 = 1;
     $i = 0;
     do {
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $filePath, $putExtra);
         $i++;
         /*
          * 503 服务端不可用
          * 504 服务端操作超时
          * 599 服务端操作失败
          */
     } while ($i < 3 and $err !== null and in_array($err->Code, array(503, 504, 599)));
     if ($err !== null) {
         throw new QiniuPutException($err->Err, $err->Code, $key);
     } else {
         return $ret['key'];
     }
 }
Ejemplo n.º 27
0
function wpjam_qiniutek_put_file($key, $file)
{
    global $qiniutek_client;
    if (!$qiniutek_client) {
        $qiniutek_client = wpjam_get_qiniutek_client();
    }
    $wpjam_qiniutek = get_option('wpjam-qiniutek');
    $qiniutek_bucket = $wpjam_qiniutek['bucket'];
    $putPolicy = new Qiniu_RS_PutPolicy($qiniutek_bucket);
    $upToken = $putPolicy->Token(null);
    if (!function_exists('Qiniu_Put')) {
        require_once WP_CONTENT_DIR . "/plugins/wpjam-qiniu/sdk/io.php";
    }
    list($ret, $err) = Qiniu_PutFile($upToken, $key, $file);
    if ($err !== null) {
        $msg = ' 发生错误:<span style="color:red">' . $err->Err . '</span><br />';
    } else {
        $msg = ' 上传成功<br />';
    }
    return $msg;
}
Ejemplo n.º 28
0
    $newname = time() . rand(10000, 99999) . '.' . $file_extension;
    /*
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    $upToken = $putPolicy->Token(null);
    list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($_FILES[$upload_name]["tmp_name"]), null);
    */
    $sql = "insert into ws_mv(mv,userid,name) values('{$newname}',{$uid},'{$newname}')";
    $res = $pdo->ExceSQL($sql, $conn);
    //		if($res){
    //			file_put_contents('./test.txt', "ok");
    //		}else{
    //			file_put_contents('./test.txt', "no");
    //		}
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    $upToken = $putPolicy->Token(null);
    $putExtra = new Qiniu_PutExtra();
    $putExtra->Crc32 = 1;
    list($ret, $err) = Qiniu_PutFile($upToken, $newname, $_FILES[$upload_name]["tmp_name"], $putExtra);
}
/**
 * up to qiniu end
 */
echo "File Received";
exit(0);
function HandleError($message)
{
    header("HTTP/1.1 500 Internal Server Error");
    echo $message;
}
Ejemplo n.º 29
0
 /**
  * Perform the file upload
  *
  * @return	bool
  */
 public function do_upload($field = 'userfile', $qiniu = FALSE)
 {
     // Is $_FILES[$field] set? If not, no reason to continue.
     if (!isset($_FILES[$field])) {
         $this->set_error('upload_no_file_selected');
         return FALSE;
     }
     // Is the upload path valid?
     if (!$this->validate_upload_path()) {
         // errors will already be set by validate_upload_path() so just return FALSE
         return FALSE;
     }
     // Was the file able to be uploaded? If not, determine the reason why.
     if (!is_uploaded_file($_FILES[$field]['tmp_name'])) {
         $error = !isset($_FILES[$field]['error']) ? 4 : $_FILES[$field]['error'];
         switch ($error) {
             case 1:
                 // UPLOAD_ERR_INI_SIZE
                 $this->set_error('upload_file_exceeds_limit');
                 break;
             case 2:
                 // UPLOAD_ERR_FORM_SIZE
                 $this->set_error('upload_file_exceeds_form_limit');
                 break;
             case 3:
                 // UPLOAD_ERR_PARTIAL
                 $this->set_error('upload_file_partial');
                 break;
             case 4:
                 // UPLOAD_ERR_NO_FILE
                 $this->set_error('upload_no_file_selected');
                 break;
             case 6:
                 // UPLOAD_ERR_NO_TMP_DIR
                 $this->set_error('upload_no_temp_directory');
                 break;
             case 7:
                 // UPLOAD_ERR_CANT_WRITE
                 $this->set_error('upload_unable_to_write_file');
                 break;
             case 8:
                 // UPLOAD_ERR_EXTENSION
                 $this->set_error('upload_stopped_by_extension');
                 break;
             default:
                 $this->set_error('upload_no_file_selected');
                 break;
         }
         return FALSE;
     }
     // Set the uploaded data as class variables
     $this->file_temp = $_FILES[$field]['tmp_name'];
     $this->file_size = $_FILES[$field]['size'];
     $this->_file_mime_type($_FILES[$field]);
     $this->file_type = preg_replace("/^(.+?);.*\$/", "\\1", $this->file_type);
     $this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
     $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
     $this->file_ext = $this->get_extension($this->file_name);
     $this->client_name = $this->file_name;
     $this->fileMD5 = md5_file($this->file_temp);
     // Is the file type allowed to be uploaded?
     if (!$this->is_allowed_filetype()) {
         $this->set_error('upload_invalid_filetype');
         return FALSE;
     }
     // if we're overriding, let's now make sure the new name and type is allowed
     if ($this->_file_name_override != '') {
         $this->file_name = $this->_prep_filename($this->_file_name_override);
         // If no extension was provided in the file_name config item, use the uploaded one
         if (strpos($this->_file_name_override, '.') === FALSE) {
             $this->file_name .= $this->file_ext;
         } else {
             $this->file_ext = $this->get_extension($this->_file_name_override);
         }
         if (!$this->is_allowed_filetype(TRUE)) {
             $this->set_error('upload_invalid_filetype');
             return FALSE;
         }
     }
     // Convert the file size to kilobytes
     if ($this->file_size > 0) {
         $this->file_size = round($this->file_size / 1024, 2);
     }
     // Is the file size within the allowed maximum?
     if (!$this->is_allowed_filesize()) {
         $this->set_error('upload_invalid_filesize');
         return FALSE;
     }
     // Are the image dimensions within the allowed size?
     // Note: This can fail if the server has an open_basdir restriction.
     if (!$this->is_allowed_dimensions()) {
         $this->set_error('upload_invalid_dimensions');
         return FALSE;
     }
     // Sanitize the file name for security
     $this->file_name = $this->clean_file_name($this->file_name);
     // Truncate the file name if it's too long
     if ($this->max_filename > 0) {
         $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
     }
     // Remove white spaces in the name
     if ($this->remove_spaces == TRUE) {
         $this->file_name = preg_replace("/\\s+/", "_", $this->file_name);
     }
     /*
      * Validate the file name
      * This function appends an number onto the end of
      * the file if one with the same name already exists.
      * If it returns false there was a problem.
      */
     $this->orig_name = $this->file_name;
     if ($this->overwrite == FALSE) {
         $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
         if ($this->file_name === FALSE) {
             return FALSE;
         }
     }
     /*
      * Run the file through the XSS hacking filter
      * This helps prevent malicious code from being
      * embedded within a file.  Scripts can easily
      * be disguised as images or other file types.
      */
     if ($this->xss_clean) {
         if ($this->do_xss_clean() === FALSE) {
             $this->set_error('upload_unable_to_write_file');
             return FALSE;
         }
     }
     /*
      * Move the file to the final destination
      * To deal with different server configurations
      * we'll attempt to use copy() first.  If that fails
      * we'll use move_uploaded_file().  One of the two should
      * reliably work in most environments
      */
     //$fileMD5 = md5_file($this->file_temp);
     $profix = substr($this->fileMD5, 0, 2);
     $upload_old = $this->upload_path;
     $this->upload_path = $this->upload_path . $profix . "/";
     if (!file_exists($this->upload_path)) {
         mkdir($this->upload_path);
         chmod($this->upload_path, 0777);
     }
     if ($qiniu) {
         //加载七牛签名SDK
         require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR . 'qiniu' . DIRECTORY_SEPARATOR . 'io.php';
         require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR . 'qiniu' . DIRECTORY_SEPARATOR . 'rs.php';
         $key = JY_getUploadFileName("10086");
         $accessKey = 'pU2VbLy6emWXs5x8Kxy2ZIKFtCHID-ghDimXM9tl';
         $secretKey = '3N2Ngow0rsEFiJzK6EoHPljza3iP55GtTwsv2WyF';
         Qiniu_SetKeys($accessKey, $secretKey);
         $putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
         $upToken = $putPolicy->Token(null);
         $putExtra = new Qiniu_PutExtra();
         $putExtra->Crc32 = 1;
         list($ret, $err) = Qiniu_PutFile($upToken, $key, $this->file_temp, $putExtra);
         if ($err !== null) {
             $this->set_error('upload_destination_error');
         } else {
             $this->qiniuData = $ret;
         }
     } else {
         if (!@copy($this->file_temp, $this->upload_path . $this->file_name)) {
             if (!@move_uploaded_file($this->file_temp, $this->upload_path . $this->file_name)) {
                 $this->set_error('upload_destination_error');
                 return FALSE;
             }
         }
     }
     //还原upload目录
     $this->upload_path = $upload_old;
     /*
      * Set the finalized image dimensions
      * This sets the image width/height (assuming the
      * file was an image).  We use this information
      * in the "data" function.
      */
     $this->set_image_properties($this->upload_path . $this->file_name);
     return TRUE;
 }
Ejemplo n.º 30
0
 /**
  * 上传文件到七牛,并获得其预览地址
  * @param  string $filePath 本地文件路径
  * @param  string $key      存储目标文件名(默认为 md5_filesize.type
  * @return string           存储后的预览URL
  */
 public static function uploadAndReturnQiniuPreviewUrl($filePath, $key = null)
 {
     if (!is_null($key)) {
         $uploadToken = W2Qiniu::getUploadTokenForQiniuUpload($key);
     } else {
         $uploadToken = W2Qiniu::getUploadTokenForQiniuUploadWithFile($filePath);
     }
     if (defined('IS_SQL_PRINT') && IS_SQL_PRINT) {
         var_export($uploadToken);
     }
     if (is_array($uploadToken) && array_key_exists('uploadToken', $uploadToken)) {
         if (array_key_exists('isFileExistInQiniu', $uploadToken) && $uploadToken['isFileExistInQiniu']) {
             return $uploadToken['urlPreview'];
         } else {
             $putExtra = new Qiniu_PutExtra();
             $putExtra->Crc32 = 1;
             list($ret, $err) = Qiniu_PutFile($uploadToken['uploadToken'], $uploadToken['SaveKey'], $filePath, $putExtra);
             if ($err !== null) {
                 throw new Exception($err, 1);
             } else {
                 return $uploadToken['urlPreview'];
             }
         }
     }
 }