I’m simply trying to loop through a folder of images and put them in an Amazon S3 bucket. I just can’t figure out why it doesn’t like the DATA part of the PUTFILE function.
If I try:
$res = $s3 -> putFile("test-bucket/".$entry);
It creates a blank file (0 bytes) in the bucket, so I know it’s connecting OK, and the filenames are correct also. I’ve also tried looping through the folders files and echoing the filenames to the screen, without using the Zend S3 function, which proved this page can access the files behind root.
The documentation regarding this function says:
putFile($path, $object, $meta) puts the content of the file in $path
into the object named $object.The optional $meta argument is the same as for putObject. If the
content type is omitted, it will be guessed basing on the source file
name.
This is what I’ve tried:
if ($handle = opendir('d:/web-library-photos/temp-previews')) {
$loopCounter = 0;
while (false !== ($entry = readdir($handle))) {
///
$loopCounter = $loopCounter + 1;
if ($loopCounter < 3) { // for test purposes only
$localPath = "d:/web-library-photos/temp-previews/".$entry;
$s3 = new Zend_Service_Amazon_S3($aws_access_key_id, $aws_s3_secret);
$res = $s3 -> putFile($localPath, "test-bucket/".$entry);
echo "Success for ".$entry.": " . ($res ? 'Yes' : 'No') . "<br>";
}
///
}
closedir($handle);
}
This particular “try” yields the error:
Cannot read file d:/web-library-photos/temp-previews/.' in C:\Inetpub\vhosts\.....thispage.php
So I thought I would try file_get_contents() and readfile() but still no luck!
Please, please, put me straight on this one – it’s driving me round the bend.
UPDATE
Right, I have a clue what’s wrong but not how to solve it.
If I simply do this:
if ($handle = opendir('d:/web-library-photos/temp-previews')) {
while (false !== ($entry = readdir($handle))) {
echo $entry."<BR>";
}
closedir($handle);
}
I get a . and a .. at the beginning of my results, which obviously can’t be read as filenames!! What is going on here, how do I get around it?

Try to append this in
while (false !== ($entry = readdir($handle)))