Jump to content

Recommended Posts

Hi

 

What i am trying to do is just show the content off a folder within one off my buckets instead off everything in the bucket?

 

So i have included the Amazon S3 class and added my credentials.

 

here is where i grab the bucket.

// Get the contents of our bucket
$contents = $s3->getBucket($amazon_bucket);

print_r($contents);

 

Ok so from the print_r i get a long array off everything in my chosen bucket here is one iteration off the array.

 Array ( [name] => dnb/Rusko - Hold On (feat. Amber Coffman) (Sub Focus Remix)(1).mp3 [time] => 1295307197 [size] => 6492663 [hash] => e5a75949ddadd924249ef8acfdded2de ) [dnb/Sleep Walk_Dub Zero_192.mp3] =>

 

So now if i run a foreach through the bucket i can grab sections out off the array.

foreach ($contents as $file){?>

$fname = $file['name'];
$furl = "http://$amazon_bucket.s3.amazonaws.com/".$fname;

<li><a class="video_click" href="<?php echo $furl; ?>" rel="prettyPhoto" title="Flash 10 demo"><?php echo "$fname"; ?></a></li>

} 

 

so instead off showing me everything in the bucket which it does, i only want it to show me everything in the dnb folder.

 

The only way i can think to do it is strip the content before the /

 

dnb/Rusko - Hold On (feat. Amber Coffman) (Sub Focus Remix)(1).mp3

 

strip the dnb then add again.

 

" add folder here "/Rusko - Hold On (feat. Amber Coffman) (Sub Focus Remix)(1).mp3

 

and then append it again has anyone got a solution for this cant find any real solutions on google any help.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/225164-amazon-s3-foreach-just-a-folder/
Share on other sites

So i have included the Amazon S3 class ...

 

Which one? There are many!

 

For what it's worth, if you use Amazon's own PHP library then you can call the AmazonS3 class's get_object_list() method with a prefix string, or regular expression, to get only the objects that you want.

 

See http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list

Did you read the documentation for the class that you're using?  You can restrict the objects returned from getBucket() by specifying a prefix.

 

See http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation#getBucket

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.