简体   繁体   English

使用AWS SDK for PHP以编程方式将文件夹添加到S3

[英]Adding folders programatically to S3 with the AWS SDK for PHP

I'm using the AWS SDK for PHP, specifically the Amazon S3 portion, and I'm not quite sure where to proceed. 我正在使用AWS SDK for PHP,特别是Amazon S3部分,我不太确定在哪里继续。 The CMS I'm developing includes the ability to manage files both locally and remotely using an S3 account. 我正在开发的CMS包括使用S3帐户在本地和远程管理文件的功能。 I want administrators to have the ability to create folders in the S3 bucket, but because S3 is a flat-file system, I'm not sure how to create an empty "folder", or at least a blank object that looks like one. 我希望管理员能够在S3存储桶中创建文件夹,但由于S3是一个平面文件系统,我不知道如何创建一个空的“文件夹”,或者至少是一个看起来像一个空白对象。 A guide I was reading (dated 2009..) mentioned suffixing the object name with _$folder$ , but I tried that and it doesn't seem to work. 我正在阅读的指南(日期为2009年...)中提到了使用_$folder$后缀对象名称,但我尝试了它并且它似乎不起作用。

It must be possible to create empty folders in an S3 bucket because the AWS console has the ability to do it, so what is the method for creating empty folders in Amazon S3? 必须可以在S3存储桶中创建空文件夹,因为AWS控制台能够执行此操作,因此在Amazon S3中创建空文件夹的方法是什么?

It looks like the AWS Console creates empty folders by creating a 0 byte file that ends in a '/' 看起来AWS Console通过创建以'/'结尾的0字节文件来创建空文件夹

eg PUT a 0 byte file called ThisisAnEmptyFolder/ 例如PUT一个名为ThisisAnEmptyFolder /的0字节文件

Then when listing the objects in a folder, the aws tools you use may return a 'file' called ThisisAnEmptyFolder/ - which users won't want to see. 然后在列出文件夹中的对象时,您使用的aws工具可能会返回一个名为ThisisAnEmptyFolder /的“文件” - 用户不希望看到它。 So you may need to include logic something like (this is NOT PHP!) 所以你可能需要包含类似的逻辑(这不是PHP!)

if (object.key != prefix)
    show the file to the user

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM