簡體   English   中英

如何編碼PHP以顯示Google Cloud Storage中的所有文件

[英]How to code PHP to display all files from 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; ?> 

然后,我想編寫另一個php來顯示我在Google Storage上存儲桶中的所有文件。 但是,我不知道該如何幫助和指導我

此代碼將允許您檢查項目中給定存儲桶中的所有文件,包括子文件夾中的文件。

<?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;
}
?>

您可以在此處查看此客戶端庫的更多選項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM