jeudi 3 septembre 2015

Laravel and AWS PHP SDK - Unable to delete a local file after it was uploaded to S3

I am trying to delete a file from a local directory right after I have uploaded it to AWS S3. When I run it on Vagrant I get an error = Text-file:busy, and when I run it on xampp I get the error :permission denied. For some reason the AWS S3 PutObject method is not releasing the file handle. I have tried to unset the s3 object but that didn't work. Thanks in advance for your help...

Here is the code:

    $tempName = public_path().'/path/to/file'

    //Initialize AWS
    $s3 = AWS::createClient('s3');


    //Upload image to AWS

    try {
        $reponse = $s3->putObject(array(
            'Bucket'       => 'zotamoda',
            'Key'          => $productImage->image_folder."/".$productImage->image_name,
            'SourceFile'   => $tempName,
            'ACL'          => 'public-read',
        ));
    } catch (S3Exception $e) {
        // The AWS error code (e.g., )
        echo $e->getAwsErrorCode() . "\n";
        // The bucket couldn't be created
        echo $e->getMessage() . "\n";
    }


    //Delete image from temporary location
    unlink($tempName);




Aucun commentaire:

Enregistrer un commentaire