stat() 공개 메소드

获取资源的元信息,但不返回文件内容
public stat ( $bucket, $key ) : array
$bucket 待获取信息资源所在的空间
$key 待获取资源的文件名
리턴 array 包含文件信息的数组,类似: [ "hash" => "", "key" => "", "fsize" => "", "putTime" => "" ]
예제 #1
0
 /**
  *   上传头像
  *   图片上传成功后做标记,渲染裁剪功能,裁剪后坐标传送给Headcut,Headcut进行裁剪,保存图片,标记。
  */
 public function actionIndex()
 {
     $accessKey = 'l5Y69nZUNTSeeqJx1LqCJP1KuLWIGU_3JVZXLzN-';
     $secretKey = '6-4HOEBkNlJpo_TuFrM9W8ZEjytRZAYjuiG0F8Df';
     $auth = new Auth($accessKey, $secretKey);
     $bucketMgr = new BucketManager($auth);
     $bucket = 'colfans-uploads-public';
     $key = 'fun.jpg';
     list($ret, $err) = $bucketMgr->stat($bucket, $key);
     echo "\n====> stat result: \n";
     if ($err !== null) {
         var_dump($err);
     } else {
         var_dump($ret);
     }
     if (!empty($_FILES['headpic'])) {
         $user = User::findByUsername(Yii::$app->user->identity->username);
         $image = UploadedFile::getInstanceByName('headpic');
         $imageName = $user->id . '_' . time() . '.' . $image->getExtension();
         if ($image->saveAs('uploads/head/' . $imageName)) {
             // file is uploaded successfully
             echo 'yes';
             die;
         } else {
             echo 'no';
             die;
         }
     } else {
         return $this->render('headupload', ['title' => '个人资料', 'category' => '账号管理', 'subcate' => '个人资料']);
     }
 }
예제 #2
0
<?php

require_once '../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);
//初始化BucketManager
$bucketMgr = new BucketManager($auth);
//你要测试的空间, 并且这个key在你空间中存在
$bucket = 'Bucket_Name';
$key = 'php-logo.png';
//获取文件的状态信息
list($ret, $err) = $bucketMgr->stat($bucket, $key);
echo "\n====> {$key} stat : \n";
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!";
}
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getMimetype($path)
 {
     $r = $this->bucketManager->stat($this->bucket, $path);
     return ['mimetype' => $r[0]['mimeType']];
 }
예제 #4
0
 /**
  * 查看文件状态
  *
  * @param $fileName
  * @return
  */
 public function checkStatus($fileName)
 {
     $bucketManager = new BucketManager($this->auth);
     list($result, $error) = $bucketManager->stat($this->bucket, $fileName);
     if (empty($result)) {
         return $error->getResponse()->error;
     } else {
         return $result;
     }
 }
예제 #5
0
if (defined('SAE_TMP_PATH')) {
    console_log("SAE_TMP_PATH: " . SAE_TMP_PATH);
    $smarty->compile_dir = SAE_TMP_PATH;
    $smarty->cache_dir = SAE_TMP_PATH;
}
//$smarty->testInstall(); exit;
$smarty->assign('ak', $ak);
$smarty->assign('sk', $sk);
$smarty->assign('bucket', $bucket);
$smarty->assign('domain', $domain);
$smarty->assign('pics', $pics);
if (count($pics) > 0) {
    $smarty->assign('sn', $sn);
    // Properties
    $props['key'] = $sn;
    list($ret, $err) = $bm->stat($bucket, $sn);
    if ($err == null) {
        $props['stat:fsize'] = $ret['fsize'];
        $props['stat:hash'] = $ret['hash'];
        $props['stat:mimeType'] = $ret['mimeType'];
        $props['stat:putTime'] = gmdate("Y-m-d H:i:s", $ret['putTime'] / 10000000);
    }
    // NROP
    $ret = Client::get("http://{$domain}/{$sn}?nrop");
    if ($ret->ok()) {
        $json = $ret->json();
        $boolarray = array(false => 'false', true => 'true');
        $props['nrop:code(0:调用成功)'] = $json['code'];
        $props['nrop:label(0:色情;1:性感;2:正常)'] = $json['fileList'][0]['label'];
        $props['nrop:rate(概率)'] = $json['fileList'][0]['rate'];
        $props['nrop:review(人工复审?)'] = $boolarray[$json['fileList'][0]['review']];