Esempio n. 1
0
 public function delete($file)
 {
     $photo = M('t_photo')->where($file)->delete();
     $info = '图片删除成功!';
     if ($photo) {
         $file = $file['name'];
         $file = str_replace("/", "_", $file);
         $setting = C('UPLOAD_SITEIMG_QINIU');
         $qiniu = new \Think\Upload\Driver\Qiniu\QiniuStorage($setting['driverConfig']);
         $info = $qiniu->del($file);
     }
     return $info;
 }
 public function _upload($order_id, $url)
 {
     $config = C('UPLOAD_TYPE_CONFIG');
     $config['domain'] = '7xlf9w.com2.z0.glb.qiniucdn.com';
     $config['bucket'] = 'zjfq-contract';
     $qiniu = new \Think\Upload\Driver\Qiniu\QiniuStorage($config);
     $upfile = array('name' => 'file', 'fileName' => $order_id . '.pdf', 'fileBody' => file_get_contents($url));
     $result = $qiniu->upload([], $upfile);
     if ($result === false) {
         $this->error = $qiniu->errorStr;
         return false;
     }
     return $qiniu->downlink($upfile['fileName']);
 }
Esempio n. 3
0
 public function get_qiniu_token()
 {
     if (empty($_SESSION['USER_ID'])) {
         exit(C('SITE_LANG.LOGIN_ALERT'));
     }
     //check login
     if (isset($_SESSION['USER_ID'])) {
         $upload_type = I('get.upload_type');
         $upload_type = $upload_type ? $upload_type : 'essay';
         $saveKey = 'img/' . $upload_type . '_' . $_SESSION['USER_ID'] . '_' . time() . '_' . md5(time() . C('SITE_PREFIX') . $this->get_random_str(8));
         $callbackUrl = C('SITE_PREFIX') . U("Action/qiniu_callback");
         //callback url
         $param = array('scope' => C('QINIU.BUCKET'), 'deadline' => 3600 + time(), 'returnUrl' => $callbackUrl, 'saveKey' => $saveKey);
         $auth = new \Think\Upload\Driver\Qiniu\QiniuStorage();
         $token = $auth->getToken(C('QINIU.SK'), C('QINIU.AK'), $param);
         $response = array('status' => 'success', 'token' => $token);
         $this->ajaxReturn($response, 'json');
     } else {
         $this->error(C('SITE_LANG.LOGIN_ALERT'), U('Action/login'));
     }
 }
Esempio n. 4
0
/**
 *  删除上传文件
 * @method delete_file($path)
 *
 * @author NewFuture
 *
 * @param $path       文件路径(url)
 * @param $storage='' 存储驱动        LOCAL QINIU SAE 等
 */
function delete_file($path, $storage = '')
{
    if (!$storage) {
        $storage = C('FILE_UPLOAD_TYPE');
    }
    switch ($storage) {
        case 'Sae':
            $arr = explode('/', ltrim($path, './'));
            $domain = array_shift($arr);
            $file_path = implode('/', $arr);
            $s = Think\Think::instance('SaeStorage');
            return $s->delete($domain, $file_path);
            break;
        case 'QINIU':
            $setting = C('UPLOAD_CONFIG_QINIU');
            $setting['timeout'] = 300;
            $url = str_replace('/', '_', $path);
            $qiniu = new Think\Upload\Driver\Qiniu\QiniuStorage($setting);
            $result = $qiniu->del($url);
            return true;
            break;
        default:
            return @unlink('./Uploads/' . $path);
            break;
    }
}