public function del($image_ids)
 {
     $image_ids = is_array($image_ids) ? $file : explode(',', $image_ids);
     $qiniu = new QiniuStorage(C("UPLOAD_QINIU_CONFIG"));
     foreach ($image_ids as $id) {
         $img = M('Picture')->find($id);
         if ($img['type'] == 'qiniu') {
             //七牛
             $qiniu->del($img['path']);
         }
         unlink($img['path']);
         //移除数据
         M('Picture')->delete($id);
     }
 }
예제 #2
0
 /**
  * 移动文件上传
  */
 public function moveUpload($files, $setting, $driver = 'Qiniu', $config = null)
 {
     $Picture = D('Picture');
     $qiniuConfig = C('UPLOAD_QINIU_CONFIG');
     $qiniuStorage = new QiniuStorage($qiniuConfig);
     $savepath = 'Uploads/atlas/';
     $file = array('name' => 'file', 'fileName' => $savepath . basename($files['name']), 'fileBody' => file_get_contents(iconv('UTF-8', 'GB2312', $files['tmp_name'])));
     // $config = array();
     $info = $qiniuStorage->upload($config, $file);
     if ($info['key']) {
         $value['md5'] = md5_file($file['tmp_name']);
         $value['sha1'] = sha1_file($file['tmp_name']);
         /* 记录文件信息 */
         if (strtolower($driver) == 'sae') {
             $value['path'] = $config['rootPath'] . 'Picture/' . $savepath . basename($files['name']);
             // 在模板里的url路径
         } else {
             if (strtolower($driver) != 'local') {
                 $value['path'] = $savepath . basename($files['name']);
             } else {
                 $value['path'] = substr($setting['rootPath'], 1) . $savepath . basename($files['name']);
                 // 在模板里的url路径
             }
         }
         $value['type'] = strtolower($driver);
         if ($Picture->create($value) && ($id = $Picture->add())) {
             $info['id'] = $id;
         } else {
             // TODO: 文件上传成功,但是记录文件信息失败,需记录日志
             unset($info[$key]);
         }
         return $info;
         // 文件上传成功
     } else {
         $this->error = '七牛上传失败';
         return false;
     }
 }
 /**
  * [qiniuUploadToken 返回七牛上传token]
  * @return [type] [description]
  */
 public function qiniuUploadToken()
 {
     $config = C('QINIU_CONFIG');
     $qiniu = new QiniuStorage($config);
     $token = $qiniu->UploadToken($qiniu->sk, $qiniu->ak, $config);
     $data = array('uptoken' => $token);
     $this->ajaxReturn($data);
 }
예제 #4
0
 public function buildSite()
 {
     $sql_format = "INSERT INTO `t_site` (`id`, `uid`, `sitename`, `address`, `sitetype`, `upper`, `city`, `money`, `phone`, `latitude`, `longitude`, `isbargain`, `intro`, `usetime`, `createtime`, `last_modify_time`, `status`) VALUES ({0}, {1}, '{2}', '{3}', '{4}', {5}, '西安', {6}, '{7}', '{8}', '{9}', 1, '{10}', '{11}', {12}, {13}, 1);\n";
     $config = array('accessKey' => 'hFFFrSwy66-vmtrYdPpLmwt7sFO_AoZFIy2F77f0', 'secretKey' => '9SkDzUhWQ6tiQFCLBMesvyo3BLa-ugideVZGTvR6', 'bucket' => 'mylineapp', 'domain' => '7xii7q.com2.z0.glb.qiniucdn.com');
     $qiniu = new QiniuStorage($config);
     $list = $qiniu->getList();
     $list = array_filter($list['items'], function ($item) {
         return $item['mimeType'] == 'image/jpeg';
     });
     $sql_format_content = "INSERT INTO `t_site_images` (`sid`, `url`) VALUES ({0}, '{1}');\n";
     for ($i = 1000000; $i < 1000000 + 100; $i++) {
         $ran1000 = mt_rand(0, 1000);
         $ran13 = mt_rand(1, 13);
         $ran4 = mt_rand(1, 4);
         $ran6 = mt_rand(1, 6);
         $latitude = 34 + mt_rand(1, 100000) / 100000;
         $longitude = 108 + mt_rand(1, 100000) / 100000;
         $sql .= $this->string_format($sql_format, $i, $ran13, '测试场地' . $i, '测试地址' . $i, '测试类型' . $ran4, 20 + $ran13, 3000 + $i, 18220512014.0 + $i, $latitude, $longitude, '测试简介' . $i, '0600,2200,12345', time(), time());
         for ($j = 0; $j < $ran6; $j++) {
             $ran = mt_rand(1, count($list));
             $sql .= $this->string_format($sql_format_content, $i, $qiniu->downLink($list[$ran]['key']));
         }
     }
     $ret = array('sql' => $sql);
     $this->ajaxReturn($ret);
 }
예제 #5
0
파일: function.php 프로젝트: noikiy/print
/**
 * 获取上传token
 * @method upload_token
 * @param  [string]       $save_name [保存的文件名]
 * @return [string]                  [上传token]
 * @author NewFuture[newfuture@yunyin.org]
 */
function upload_token($save_name)
{
    $config = C('UPLOAD_CONFIG_QINIU');
    $timeout = 300;
    $setting = array('scope' => $config['bucket'] . ':' . $save_name, 'deadline' => $timeout + time());
    $token = \Think\Upload\Driver\Qiniu\QiniuStorage::SignWithData($config['secretKey'], $config['accessKey'], json_encode($setting));
    return $token;
}