/** * 执行一次批量操作 * !!!注意:如果参数中设置了$ops数组,将自动忽略并清空所有通过 batch_add_*添加的操作序列 * * @param array $ops 需要执行的操作的组合,需要符合以下格式: * $ops = array( * [0] => array ( * 'op' => 'xxxx', * 'param' => array (xxxx) * ), * [1] => array (...... * .... * ) ) * * @since v1.0 * @return Qiniu_response * @throws Qiniu_RS_Exception */ public function do_batch($ops = array()) { if (!empty($ops)) { $this->_batch_ops = $ops; } $op_arr = array(); foreach ($this->_batch_ops as $op) { if (isset($op['op']) && isset($op['param']) && is_array($op['param'])) { switch ($op['op']) { case 'stat': case 'delete': try { $file = $this->_filename_to_array($op['param'][0]); $op_arr[] = "/{$op['op']}/" . $this->auth->url_safe_base64_encode("{$file['bucket']}:{$file['key']}"); } catch (Exception $e) { throw new Qiniu_RS_Exception('Invalid Params In Doing Batch Request'); } break; case 'copy': case 'move': try { $src = $this->_filename_to_array($op['param'][0]); $dest = $this->_filename_to_array($op['param'][1]); $uri = "/{$op['op']}/" . $this->auth->url_safe_base64_encode("{$src['bucket']}:{$src['key']}") . '/'; $uri .= $this->auth->url_safe_base64_encode("{$dest['bucket']}:{$dest['key']}"); $op_arr[] = $uri; } catch (Exception $e) { throw new Qiniu_RS_Exception('Invalid Params In Doing Batch Request'); } break; default: continue; } } else { throw new Qiniu_RS_Exception('Invalid Params In Doing Batch Request'); } } $body = 'op=' . implode('&op=', $op_arr); $req = new Qiniu_request($this->_rs_host . '/batch', $body); $req->set_header('Content-Type', 'application/x-www-form-urlencoded'); $token = $this->auth->sign_request($this->_rs_host . '/batch', $body); $req->set_header('Authorization', 'QBox ' . $token); $resp = $req->make_request(); return $resp; }
/** * 上传一个字符串到七牛,并存储为指定的文件名 * * @since v1.0 * @param string $filetoupload 要上传的文件(文件路径) * @param string $saveKey 要存储为的文件名(如果让七牛设置可将此参数置为空) * @param string $saveBucket 要上传到的空间名(为空时表示使用默认的Bucket) * @param bool $use_custom_put_policy 是否使用自定义的上传策略 * 设置这个参数为TRUE时需要使用Qiniu_put_policy类设置上传策略,函数将会自动调用 * @param int $expired 上传执行的有效期 * @return string|Qiniu_response */ function upload_string($strtoupload, $saveKey, $saveBucket = '', $use_custom_put_policy = FALSE, $expired = 7200) { $pp = $this->put_policy; if (!$use_custom_put_policy) { $pp->clear_policy(); $policy = array(); //判断传入的savename是一个Bucket名还是一个Bucket:key的数组 if (empty($saveBucket)) { $saveBucket = $this->_bucket; } if (empty($saveKey)) { $policy[Qiniu_put_policy::QINIU_PP_SCOPE] = $saveBucket; } else { $policy[Qiniu_put_policy::QINIU_PP_SCOPE] = $saveBucket . ':' . $saveKey; } $policy[Qiniu_put_policy::QINIU_PP_DEADLINE] = time() + $expired; //设置上传策略 $pp->set_policy_array($policy); } //获取上传Token $token = $pp->get_token(); $param['token'] = $token; $param['key'] = $saveKey; $the_file['files']['file'] = array($saveKey, $strtoupload); // list($boundary, $body) = $this->buildMultiForm($param, $the_file['files']); $req = new Qiniu_request($this->_up_host, $body); $req->set_header('Content-Type', 'multipart/form-data; boundary=' . $boundary); $resp = $req->make_request(); return $resp; }
/** * 获取指定图片资源的EXIF信息 * * @since v1.2 * * @param $filename * @return Qiniu_response * @throws Qiniu_Exception */ public function exif($filename) { $url = $this->dl->get_url($filename, FALSE, NULL, 7200, 'exif'); $req = new Qiniu_request($url); $resp = $req->make_request('GET'); return $resp; }