file_manager_json.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace qiniu\upload;
  3. /****************************************************
  4. * NKeditor PHP
  5. * 本PHP程序是演示程序,建议不要直接在实际项目中使用。
  6. * 如果您确定直接使用本程序,使用之前请仔细确认相关安全设置。
  7. * **************************************************
  8. * 获取图片服务器上已上传的图片列表
  9. * @author yangjian<yangjian102621@gmail.com>
  10. */
  11. use Qiniu\Auth;
  12. use Qiniu\Storage\BucketManager;
  13. require_once "vendor/autoload.php";
  14. require_once "../JsonResult.php";
  15. require_once "config.php";
  16. require_once "../functions.php";
  17. $page = intval($_GET["page"]);
  18. $fileType = trim($_GET['fileType']);
  19. if ($fileType == '') {
  20. $fileType = "image";
  21. }
  22. $marker = trim($_GET['marker']); //上次列举返回的位置标记,作为本次列举的起点信息。
  23. if ($marker == "no_records") {
  24. \JsonResult::fail("没有更多的文件了");
  25. }
  26. // 构建鉴权对象
  27. $auth = new Auth(QINIU_ACCESS_KEY, QINIU_SECRET_KEY);
  28. $bucketManager = new BucketManager($auth);
  29. // 要列取文件的公共前缀
  30. $prefix = $fileType."-";
  31. // 本次列举的条目数
  32. $limit = 15;
  33. $delimiter = '/';
  34. list($ret, $err) = $bucketManager->listFiles(QINIU_TEST_BUCKET, $prefix, $marker, $limit, $delimiter);
  35. $result = new \JsonResult();
  36. if ($err !== null) {
  37. $result->setCode(\JsonResult::CODE_FAIL);
  38. $result->setMessage($err);
  39. } else {
  40. $files = array();
  41. $result->setCode(\JsonResult::CODE_SUCCESS);
  42. foreach($ret["items"] as $value) {
  43. $filename = $value['key'];
  44. if (strpos($value['mimeType'], 'image') !== false) { //如果是图片则获取尺寸
  45. $imgSize = getImgSize($value['key']);
  46. }
  47. array_push($files, array(
  48. "thumbURL" => QINIU_BUCKET_DOMAIN.$filename,
  49. "oriURL" => QINIU_BUCKET_DOMAIN.$filename,
  50. "filesize" => $value['fsize'],
  51. "width" => intval($imgSize["width"]),
  52. "height" => intval($imgSize["height"])));
  53. }
  54. $result->setData($files);
  55. if (array_key_exists('marker', $ret)) {
  56. $result->setExtra($ret['marker']);
  57. } else {
  58. $result->setExtra("no_records");
  59. }
  60. }
  61. $result->output();