简体   繁体   English

如何编码PHP以显示Google Cloud Storage中的所有文件

[英]How to code PHP to display all files from Google Cloud Storage

Now I had done the php code to upload file to google cloud storage 现在我已经完成了php代码以将文件上传到Google云存储

 <?php use google\\appengine\\api\\cloud_storage\\CloudStorageTools; $bucket = '<your bucket name>'; // your bucket name $root_path = 'gs://' . $bucket . '/'; $_url = ''; if(isset($_POST['submit'])) { if(isset($_FILES['userfile'])) { $name = $_FILES['userfile']['name']; $file_size =$_FILES['userfile']['size']; $file_tmp =$_FILES['userfile']['tmp_name']; $original = $root_path .$name; move_uploaded_file($file_tmp, $original); $_url=CloudStorageTools::getImageServingUrl($original); } } ?> <html> <body> <form action="#" method="post" enctype="multipart/form-data"> Send these files: <p/> <input name="userfile" type="file" /> <p/> <input type="submit" name="submit" value="UPLOAD" /> </form> </body> </html> <?php echo $_url; ?> 

Then I would like to code another php to display all files in my bucket on Google Storage. 然后,我想编写另一个php来显示我在Google Storage上存储桶中的所有文件。 But, I don't know how to Please help and guide me 但是,我不知道该如何帮助和指导我

This code will allow you to check all the files in a given bucket in your project, including the ones in a subfolder. 此代码将允许您检查项目中给定存储桶中的所有文件,包括子文件夹中的文件。

<?php
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$projectId = 'PROJECT-ID';

$bucketName = 'YOUR-BUCKET';
$storage = new StorageClient([    
'projectId' => $projectId
]);
$bucket = $storage->bucket($bucketName);
$listObjects = $bucket->objects(['fields' => 
    'items/name,nextPageToken'
]);
foreach ($listObjects as $item) {           
    echo $item->name() . PHP_EOL;
}
?>

You can see more options for this client library in here 您可以在此处查看此客户端库的更多选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 PHP 列出 Google Cloud Storage 中存储桶中的所有文件? - How to list all the files from a bucket in Google Cloud Storage using PHP? 如何使用PHP备份服务器文件将文件从服务器上传到Google云存储到Google服务器? - How can I upload files to google cloud storage from my server to google's server using PHP to backup my server files? 没有AppEngine的Google云存储上的PHP文件 - PHP files on Google cloud storage without AppEngine 是否可以仅使用 Authorization Bearer Token 和 Bucket 名称将文件上传到谷歌云存储? (PHP代码) - Is it possible to upload files to google cloud storage with just Authorization Bearer Token and Bucket name? (php code) PHP Google云端存储 - PHP Google Cloud Storage 如何使用php将pdf上传到Google云存储? - How to upload a pdf to google cloud storage with php? 如何使用Google Cloud Storage for PHP? - How to use Google Cloud Storage for PHP? 通过 Google Cloud Storage 中的 PHP 服务器提供文件的最有效方法? - Most efficient way to serve files through a PHP server from Google Cloud Storage? 使用PHP将文件上传到Google Cloud Storage Bucket - Upload files to Google Cloud Storage Bucket using PHP Google App Engine:如何在 PHP 循环中从 Google 云存储提供上传的图像 - Google App Engine: How to serve uploaded images in a PHP loop from google cloud storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM