I am using the AWS PHP SDK to move files from our server to S3, after they have been moved I want to delete them to save space on our server. But when I attempt to do this I get an PHP warning: Text file busy in /path/to/file
.
If I understand it correctly I assume the file is still being uploaded to S3 when I attempt to delete it. I've looked for some kind of callback like uploadComplete
for S3 but cannot find anything.
Here is a sample of my code:
//Upload dir:
$result = false;
try{
$result = $this->aws['s3']->uploadDirectory(
$options['dir'],
$options['bucket'],
$options['key'], array(
'before' => function(\AWS\Command $command){
$command['ACL'] = 'public-read';
})
);
} catch (S3Exception $e) {
error_log('AWS ERR, failed to add object to bucket: '.$e->getMessage());
}
if ($result) {
//remove local copy
array_map('unlink', glob("$options['dir']/*.*"));
rmdir($options['dir']);
}
So, how can I delete a directory or file after uploading to S3?