2

I not only want to upload files to s3, but also want to remove those deleted files from s3.

For example, I have these 2 files on s3: black.jpg, red.jpg

I have these files in my local directory: black.jpg, green.jpg

I want a function that will upload green.jpg to s3 and delete red.jpg from s3. Is it possible?

1 Answer 1

3

Get an array of files with $s3->listObjects(); and a array of local files with readDir();

$uploadList = array_diff($localFiles, $s3Files); // returns green.jpg

$deleteList = array_diff($s3Files, $localFiles); // returns red.jpg

Loop over $uploadList and call $s3->putObject()

Loop over $deleteList and call $s3->deleteObject()


Check out AWS PHP SDK documentation for the necessary method parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.