function recursiveGetStorage($bucketName, $path, $context = null) { global $storage, $fileNum, $dirNum; $listRet = Cosapi::listFolder($bucketName, $path, 199, null, null, $context); //var_dump($listRet); while ($listRet && $listRet['code'] === 0 && $listRet['data']['infos']) { foreach ($listRet['data']['infos'] as $item) { if (isset($item['filelen'])) { $fileNum++; $storage += $item['filesize']; if ($item['filelen'] != $item['filesize']) { echo "{$path}" . $item['name'] . " filesize:" . $item['filesize'] . " filelen:" . $item['filelen'] . "\n"; } } else { $dirNum++; recursiveGetStorage($bucketName, $path . $item['name'] . '/'); } } $context = $listRet['data']['context']; $listRet = Cosapi::listFolder($bucketName, $path, 10, null, null, $context); //var_dump($listRet); } if ($listRet['code'] !== 0) { echo "{$path} has error, code:" . $listRet['code'] . "\n"; } return; }
$sliceSize = 3 * 1024 * 1024; $uploadRet = Cosapi::upload($bucketName, $srcPath, $dstPath, $bizAttr, $sliceSize, $insertOnly); var_dump($uploadRet); //目录列表 $listnum = 20; $pattern = "eListBoth"; $order = 0; $listRet = Cosapi::listFolder($bucketName, $dstFolder, $listnum, $pattern, $order); var_dump($listRet); //更新目录信息 $bizAttr = ""; $updateRet = Cosapi::updateFolder($bucketName, $dstFolder, $bizAttr); var_dump($updateRet); //更新文件信息 $bizAttr = ""; $authority = "eWPrivateRPublic"; $customer_headers_array = array('Cache-Control' => "no", 'Content-Type' => "application/pdf", 'Content-Language' => "ch"); $updateRet = Cosapi::update($bucketName, $dstPath, $bizAttr, $authority, $customer_headers_array); var_dump($updateRet); //查询目录信息 $statRet = Cosapi::statFolder($bucketName, $dstFolder); var_dump($statRet); //查询文件信息 $statRet = Cosapi::stat($bucketName, $dstPath); var_dump($statRet); //删除文件 $delRet = Cosapi::delFile($bucketName, $dstPath); var_dump($delRet); //删除目录 $delRet = Cosapi::delFolder($bucketName, $dstFolder); var_dump($delRet);
<?php // include Config File & QCLOUD COS SDk require './config.inc.php'; use Qcloud_cos\Auth; use Qcloud_cos\Cosapi; //include Slim2 require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->get('/', function () { echo "Hello World!"; }); $app->get('/:dir', function ($dir) { $dir = str_replace('-', '/', $dir); $listRet = Cosapi::listFolder(BUCKET, $dir); $listRet = $listRet['data']; $listRet = json_encode($listRet); echo $listRet; }); $app->run();
exit("0"); } } $files = time(); //传到COS $base64_body = substr(strstr($base64_image_content, ','), 1); //生成本地文件 $new_file = "./tmp/" . $files . ".png"; $data = base64_decode($base64_body); file_put_contents($new_file, $data); $cosfolder = Cosapi::statFolder($bucketName, $faceFolder); if ($cosfolder["code"] != "0") { Cosapi::createFolder($bucketName, $faceFolder); } //要传入腾讯云文件 $dstPath = $faceFolder . $files . ".png"; //查询文件是否存在 $result = Cosapi::stat($bucketName, $dstPath); if ($result["code"] == "0") { Cosapi::del($bucketName, $dstPath); $types = Cosapi::upload($new_file, $bucketName, $dstPath); } else { $types = Cosapi::upload($new_file, $bucketName, $dstPath); } /*清空本地的存储文件及目录 unlink($save_path); */ $file_url = $types["data"]["access_url"]; session_start(); $_SESSION['face'] = $file_url; echo "1";
/** * 删除远程服务器上的单个文件 */ function delete_remote_file($file) { //获取WP配置信息 $cos_options = get_option('cos_options', TRUE); $cos_bucket = esc_attr($cos_options['bucket']); //得到远程路径 $file = str_replace("\\", '/', $file); $del_file_path = str_replace(get_home_path(), '/', $file); try { //实例化存储对象 $qcloud_cos = new Cosapi(); //删除文件 $qcloud_cos->del($cos_bucket, $del_file_path); } catch (Exception $ex) { } return $file; }
//var_dump($uploadRet); //分片上传 //$sliceUploadRet = Cosapi::upload_slice( // $srcPath, $bucketName, $dstPath); //用户指定分片大小来分片上传 //$sliceUploadRet = Cosapi::upload_slice( // $srcPath, $bucketName, $dstPath, null, 3*1024*1024); //指定了session,可以实现断点续传 //$sliceUploadRet = Cosapi::upload_slice( // $srcPath, $bucketName, $dstPath, null, 2000000, '48d44422-3188-4c6c-b122-6f780742f125+CpzDLtEHAA=='); //var_dump($sliceUploadRet); //创建目录 //$createFolderRet = Cosapi::createFolder($bucketName, "/test/"); //var_dump($createFolderRet); //listFolder $listRet = Cosapi::listFolder($bucketName, "/"); var_dump($listRet); //prefixSearch //$ret = Cosapi::prefixSearch($bucketName, "/test"); //var_dump($ret); //updateFolder //$updateRet = Cosapi::updateFolder($bucketName, '/test/', '{json:0}'); //var_dump($updateRet); //update //$updateRet = Cosapi::update($bucketName, $dstPath, '{json:1}'); //var_dump($updateRet); //statFolder //$statRet = Cosapi::statFolder($bucketName, "/test/"); //var_dump($statRet); //stat //$statRet = Cosapi::stat($bucketName, $dstPath);
//移动文件 $file_path = $save_path . $new_file_name; if (move_uploaded_file($tmp_name, $file_path) === false) { alert("上传文件失败。"); } //本地文件 $srcPath = $file_path; //要传入腾讯云文件 $dstPath = "/attached/" . $dir_name . "/" . $ymd . "/" . $new_file_name; //查询文件是否存在 $result = Cosapi::stat($bucketName, $dstPath); if ($result["code"] == "0") { Cosapi::del($bucketName, $dstPath); $types = Cosapi::upload($srcPath, $bucketName, $dstPath); } else { $types = Cosapi::upload($srcPath, $bucketName, $dstPath); } /*清空本地的存储文件及目录 unlink($file_path); rmdir("./tmp/".$dir_name."/".$ymd); rmdir("./tmp/".$dir_name); */ //完整的URL路径 $file_url = $types["data"]["access_url"]; header('Content-type: text/html; charset=UTF-8'); $json = new Services_JSONs(); echo $json->encode(array('error' => 0, 'url' => $file_url)); exit; } function alert($msg) {