delete() 공개 메소드

删除指定资源
public delete ( $bucket, $key ) : mixed
$bucket 待删除资源所在的空间
$key 待删除资源的文件名
리턴 mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
예제 #1
0
파일: Upload.php 프로젝트: huagenlike/space
 /**
  * 删除图片
  * $param string $fileName 图片名称
  * return null
  */
 public function deleteFile($fileName)
 {
     $bucketMgr = new BucketManager($this->auth);
     $err = $bucketMgr->delete($this->bucket, $fileName);
     if ($err !== null) {
         return $err;
     } else {
         return "Success!";
     }
 }
예제 #2
0
 public function fire($job, $keys)
 {
     $qiniu_config = Config::get('qiniu');
     $auth = new Auth($qiniu_config['accessKey'], $qiniu_config['secretKey']);
     $bucket_manager = new BucketManager($auth);
     foreach ($keys as $key) {
         $response = $bucket_manager->delete($qiniu_config['buckets'][0], $key);
         if ($response) {
             Log::info("Error in delete key:{$key}" . $response->message());
         }
     }
 }
예제 #3
0
 /**
  *   上传头像
  *   图片上传成功后做标记,渲染裁剪功能,裁剪后坐标传送给Headcut,Headcut进行裁剪,保存图片,标记。
  */
 public function actionIndex()
 {
     //如果用户上传了头像图片
     if (!empty($_FILES['headpic'])) {
         //进行本地上传
         $user = User::find()->where(['id' => $_GET['id']])->one();
         $image = UploadedFile::getInstanceByName('headpic');
         $imageName = $user->id . '_' . time() . '.' . $image->getExtension();
         if ($image->saveAs('uploads/head/' . $imageName)) {
             //上传到本地成功,进行图片处理
             //组装文件名
             $imagePath = Yii::getAlias('@root') . '\\frontend\\web\\uploads\\head\\' . $imageName;
             // 处理成功后 传入七牛
             //配置七牛的参数
             $accessKey = Yii::getAlias('@accessKey');
             $secretKey = Yii::getAlias('@secretKey');
             $auth = new Auth($accessKey, $secretKey);
             $bucket = 'colfans-uploads-public';
             $token = $auth->uploadToken($bucket);
             $uploadMgr = new UploadManager();
             list($ret, $err) = $uploadMgr->putFile($token, $imageName, $imagePath);
             if ($err !== null) {
                 //上传不成功
                 echo 'no';
             } else {
                 //上传成功
                 //删除本地文件
                 unlink($imagePath);
                 //更新数据库头像
                 $oldHeadFile = $user->head;
                 $user->head = $imageName;
                 if ($user->save()) {
                     //删除七牛原有的头像图片
                     $bucketMgr = new BucketManager($auth);
                     $err = $bucketMgr->delete($bucket, $oldHeadFile);
                     if ($err !== null) {
                         echo 'no';
                     } else {
                         echo 'yes';
                     }
                 }
             }
         } else {
         }
     } else {
         return $this->render('headupload', ['title' => '个人资料', 'category' => '账号管理', 'subcate' => '个人资料']);
     }
 }
 public function deleteImageByQiniuKey($key)
 {
     vendor("qiniusdk.autoload");
     $accessKey = 'k7HBysPt-HoUz4dwPT6SZpjyiuTdgmiWQE-7qkJ4';
     $secretKey = 'BuaBzxTxNsNUBSy1ZvFUAfUbj8GommyWbfJ0eQ2R';
     //初始化Auth状态
     $auth = new Auth($accessKey, $secretKey);
     //初始化BucketManager
     $bucketMgr = new BucketManager($auth);
     $bucket = 'image';
     if ($key == "") {
         return false;
     } else {
         $err = $bucketMgr->delete($bucket, $key);
         if ($err !== null) {
             return false;
         } else {
             return true;
         }
     }
 }
예제 #5
0
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}
//将文件从文件$key 复制到文件$key2。 可以在不同bucket复制
$key2 = 'php-logo2.png';
$err = $bucketMgr->copy($bucket, $key, $bucket, $key2);
echo "\n====> copy {$key} to {$key2} : \n";
if ($err !== null) {
    var_dump($err);
} else {
    echo "Success!";
}
//将文件从文件$key2 移动到文件$key3。 可以在不同bucket移动
$key3 = 'php-logo3.png';
$err = $bucketMgr->move($bucket, $key2, $bucket, $key3);
echo "\n====> move {$key2} to {$key3} : \n";
if ($err !== null) {
    var_dump($err);
} else {
    echo "Success!";
}
//删除$bucket 中的文件 $key
$err = $bucketMgr->delete($bucket, $key3);
echo "\n====> delete {$key3} : \n";
if ($err !== null) {
    var_dump($err);
} else {
    echo "Success!";
}
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function delete($path)
 {
     return $this->bucketManager->delete($this->bucket, $path);
 }
예제 #7
0
파일: Qiniu.php 프로젝트: leunico/aliceBlog
 public function Delete($filename)
 {
     $Bucket = new BucketManager($this->auth);
     $err = $Bucket->delete($this->bucket, $filename);
     return $err !== null ? '' : true;
 }
예제 #8
0
 /**
  * 推送图片
  **/
 public function actionpushimage()
 {
     $res = array("status" => 0, "mes" => "", "data" => array(), "image_url" => "");
     $brandid = isset($_SESSION['brandid']) ? $_SESSION['brandid'] : 0;
     //品牌ID
     $userid = $_SESSION['user_id'];
     //用户ID
     $push_detaile = Yii::app()->request->getParam("push_detaile");
     //推送信息
     $cut_detaile = Yii::app()->request->getParam("cut_detaile");
     //裁剪信息
     $imageid = Yii::app()->request->getParam("imageid");
     //图片ID
     $skc = Yii::app()->request->getParam("skc");
     //衣服skc
     try {
         //通过图片ID查找图片信息
         $image_obj = Yii::app()->db->createCommand()->select('url,name')->from('erp_image')->where("id={$imageid}")->queryRow();
         $image_url = "";
         $image_name = "";
         if (!empty($image_obj)) {
             $image_url = $image_obj['url'];
             //衣服图片原图
             $res['image_url'] = $image_obj['url'];
             //衣服名
         } else {
             throw new Exception('图片信息无法获取');
         }
         $pushdetaile_class = new pushDetaileclass();
         $array = array("watermark_id" => $push_detaile['watermarkid'], "watermark_width" => $cut_detaile['watermarkwidth'], "watermark_height" => $cut_detaile['watermarkheight'], "watermark_url" => $push_detaile['watermarkurl'], "watermark_positionx" => $cut_detaile['positionx'], "watermark_positiony" => $cut_detaile['positiony'], "patform_width" => $cut_detaile['width'], "patform_height" => $cut_detaile['height'], "image_url" => $image_url, "cut_positionx" => $push_detaile['positionx'], "cut_positiony" => $push_detaile['positiony'], "cut_width" => $push_detaile['CutOut_width'], "cut_height" => $push_detaile['CutOut_height'], "img_w" => $push_detaile['img_w'], "img_h" => $push_detaile['img_h']);
         $end_obj = $pushdetaile_class->cut_image($array, $brandid);
         //print_r($end_obj);
         if ($end_obj['status'] == 0) {
             throw new Exception('图片生成失败');
         }
         $qiniu_image_url = $end_obj['url'];
         $qiniu_array = $end_obj['qiniu_array'];
         //裁剪完成的数据
         if (count($qiniu_array) == 0) {
             throw new Exception('七牛账户信息有误');
         }
         //access_key、secret_key、space、domain
         $status = 1;
         //1为失败,0为成功
         $content = @file_get_contents($qiniu_image_url);
         if ($content) {
             $imagename = md5($qiniu_image_url);
             $image = $content;
             $ProcessImagepath = $_SERVER['DOCUMENT_ROOT'] . "/uploads/image/" . $imagename . ".jpg";
             $fp = fopen($ProcessImagepath, 'w');
             fwrite($fp, $image);
             //写入文件
             fclose($fp);
             $image_array = explode("/", $image_url);
             $file = "";
             $image_count = count($image_array);
             for ($i = 0; $i < $image_count; $i++) {
                 if ($i == $image_count - 1) {
                     $file .= $imagename . ".jpg";
                 } else {
                     $file .= $image_array[$i] . "/";
                 }
             }
             $key3 = $file;
             $bucket = $qiniu_array[0]['space'];
             $auth = new Auth($qiniu_array[0]['access_key'], $qiniu_array[0]['secret_key']);
             $bucketMgr = new BucketManager($auth);
             //删除$bucket 中的文件 $key
             $err = $bucketMgr->delete($bucket, $key3);
             $uploadfile_ret = $this->qinuu_upload($file, $ProcessImagepath);
             @unlink($ProcessImagepath);
             if (!isset($uploadfile_ret[0]['hash'])) {
                 throw new Exception('图片上传失败');
             }
             /*******推送到平台***start***/
             /*******推送到平台***end***/
             $status = 0;
             //修改推送数据
             $pushdetaile_class->update_push($push_detaile['id'], array('pushstatus' => 1, 'cut_src' => $file));
             $res['status'] = 1;
         }
         $pushcount_array = array('skc' => $push_detaile['skc'], 'sku' => $push_detaile['sku'], 'addtime' => date("Y-m-d H:i:s"), 'patformid' => $cut_detaile['patformid'], 'status' => $status, 'clothesimageid' => $imageid, 'userid' => $userid, 'brandid' => $brandid);
         $pushcount_class = new pushcountclass();
         $pushcount_class->insert_push_count($pushcount_array);
         //插入信息
         $res['id'] = $push_detaile['imageid'];
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     echo json_encode($res);
     exit;
 }
예제 #9
0
 /**
  * 删除指定文件
  * @param $fileName
  * @return mixed
  */
 public function delete($fileName)
 {
     $client = new BucketManager($this->auth);
     return $client->delete($this->bucket, $fileName);
 }
예제 #10
0
파일: Qiniu.php 프로젝트: andygoo/admin
 protected function _del_hc51($key)
 {
     $qiniu_config = Kohana::config('qiniu.haoche51');
     $accessKey = $qiniu_config['access_key'];
     $secretKey = $qiniu_config['secret_key'];
     $bucket = 'haoche51post';
     $auth = new Auth($accessKey, $secretKey);
     $bucketMgr = new BucketManager($auth);
     $err = $bucketMgr->delete($bucket, $key);
     if ($err === null) {
         return true;
     } else {
         return false;
     }
 }
예제 #11
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model = $this->loadModel($id);
     $accessKey = 'alO3SWK6jx4XvPSeUCbhRRb8arS8sivFSQ_zMo1K';
     $secretKey = 'qZlz5D8-Wlj0nUnsRt-qTNit56dVcWb2jK_eVqcK';
     //初始化Auth状态:
     $auth = new Auth($accessKey, $secretKey);
     //初始化BucketManager
     $bucketMgr = new BucketManager($auth);
     //你要测试的空间, 并且这个key在你空间中存在
     $bucket = 's-nice';
     $key = $model->img;
     //删除$bucket 中的文件 $key
     $err = $bucketMgr->delete($bucket, $key);
     if (file_exists(Yii::app()->params['uploadPath'] . $model->img)) {
         unlink(Yii::app()->params['uploadPath'] . $model->img);
     }
     $model->delete();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
     }
 }
예제 #12
0
 /**
  * 删除图片
  * @param  [type] $imgName [文件名]
  * @return [type]          [description]
  */
 public function delImage($imgName)
 {
     $bucketMgr = new BucketManager($this->auth);
     $err = $bucketMgr->delete($this->bucket, $imgName);
     return $this->response($err);
 }