Here, I’m giving an example to insert a object to S3 using Zend PHP framework. Zend itself had built in library classes to communicate with AWS S3. So things are very easy. Lets see how to do this. First we have to login to AWS console using the credentials which you had. Select S3 console. You can create S3 bucket directly through AWS console or can create through code itself. Refer the example given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //Declaring the S3 class library object $awsS3 = new Zend_Service_Amazon_S3(< S3ACCESSKEY >, < S3SECRETKEY >); //Checking the S3 Bucket exists or not if ($awsS3->isBucketAvailable(< S3BUCKETNAME >) == "") { $awsS3->createBucket(< S3BUCKETNAME >); } //Checking Whether the object with same name existing or not. If it is exists, we can either remove and add the new one or choose a different name for the file to be uploaded. //Remove the object if it is already exists if ($awsS3->isBucketAvailable(< S3BUCKETNAME >) && $awsS3->isObjectAvailable(< S3BUCKETNAME > . "/" . <filename>)) { $awsS3->removeObject(< S3BUCKETNAME > . "/" . <filename>); } $FileTemp = $_FILES['myvideofile']['tmp_name']; //Insert an object with Public Read permission $awsS3->putObject(< S3BUCKETNAME > . "/" . < file name>, file_get_contents($FileTemp), array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ)); |