You can’t rename objects in S3, you have to copy them to a new object name and then delete the original


//----- SET THE FILE NAME EXTENSION TO MATCH THE USER UPLOADED FILE -----
require_once 'my_sdk_files_path/sdk.class.php';				//<<<<SET THIS

$s3 = new AmazonS3();
$bucket = "my_bucket_name";				//<<<<SET THIS

//GET THE USERS FILENAME EXTENSION
$filename_extension = pathinfo($uploaded_source_file_name, PATHINFO_EXTENSION);

//COPY THE FILE ADDING THE FILENAME EXTENSION TO THE DESTIANTION FILENAME
$s3_result = $s3->copy_object(
	 array( 'bucket' => $bucket, 'filename' => $uploaded_dest_file_name ),
	 array( 'bucket' => $bucket, 'filename' => $uploaded_dest_file_name . '.' . $filename_extension )
);
echo "<br />Worked: ";
var_dump($s3_result->isOK());			//Did it work?
echo "<br />Status: ";	
var_dump($s3_result->status);			//HTTP status

//DELETE THE ORIGINAL FILE
echo "<br />Deleting original file";
$s3_result = $s3->delete_object($bucket, $uploaded_dest_file_name);

echo "<br />Worked: ";					//Did it work?
var_dump($s3_result->isOK());
echo "<br />Status: ";					//HTTP status
var_dump($s3_result->status);
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.