I am using Amazon S3 to store photos uploaded by users, using the following code:
if(isset($_POST['Submit'])){
$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];
$folderName = "{id}/{address}/$fileName";
//create a new bucket
$s3->putBucket("bucket_name", S3::ACL_PUBLIC_READ);
//move the file
if ($s3->putObjectFile($fileTempName, "bucket_name", $folderName, S3::ACL_PUBLIC_READ)) {
echo ""; //etc, etc
The {id}
and {address}
are dynamic variables used to create the appearance of folders when the files are uploaded, based on each user's unique data stored in a mysql database.
The problem I'm having is displaying these files inside each user's password protected site. The code I'm using below pics up ALL user's photos and displays them to ALL users. If {id}/{address}/$fileName
converts to 123/figuero/photo.jpg
then user 123
should only be able to see 123/figuero/photo.jpg
(or any other files with the preface 123/
or 123/xxx/
With the code I'm using below, ALL files inside bucket_name
can be seen by ALL users, instead of just the files associated with the dynamic data associated with their photos:
<ul>
<?php
$i = 0;
$contents = $s3->getBucket("bucket_name");
foreach($contents as $file)
{
$fname = $file['name'];
$furl = 'http://bucket_name.s3.amazonaws.com/'.$fname;
echo "<li><img src='$furl'></li>";
{
$i = 0;
}
}
?>
<ul>
In other words, ALL the files inside http://bucket_name.S3.amazonaws.com/ are being pulled up for display by the code, instead of just the photos pertaining to user 123
inside the files prefaced by 123/xxx/
What am I missing? Thanks much in advance.