[英]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.