I had the same problem and Shahin's answer is correct, you can set
'Body' => fopen($tmpFile, 'r'),
However when I did this on my WAMP localhost, I got the error
Warning: fopen(C:\Windows\Temp\phpBDF3.tmp): failed to open stream: No such file or directory
This seems to be a windows permissions issue, and you can resolve it by copying the windows temp file to another temp file in a directory where there are no permissions problems (eg web root):
// $tmpFile was 'C:\Windows\Temp\php8A16.tmp';
// create a new temp file in webroot, and copy the windows tempfile there
$new_temp_location = tmpfile();
$new_temp_location = basename($tmpFile);
copy($tmpFile, $new_temp_location);
// now put the file in the bucket
try {
$s3->putObject(array(
'Bucket' => $bucketname,
'Key' => $filename,
'Body' => fopen($new_temp_location, 'r'),
'ACL' => 'public-read',
'ContentType' => $imageType,
'StorageClass' => 'STANDARD'
));
} catch (S3Exception $e) {
echo "There was an error uploading the file.\n";
}
It worked for me - hope it saves someone else some time...
EDIT:
Or slightly simpler, you can use
'SourceFile' => $new_temp_location,
Instead of
'Body' => fopen($new_temp_location, 'r'),