Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Image uploading to using S3 --
- public static function imageUploading($image){
- if(isset($image)){
- if($image->isValid()){ //Determining If An Uploaded File Is Valid
- //Retrieving The Extension Of An Uploaded File
- $extension = $image->getClientOriginalExtension();
- //change filename to a random sha1 plus current time
- $filename = "img_" . substr(sha1(time().time()), 0, 15) .".{$extension}";
- //define directory to store images
- $directory = 'uploads/images/'.$filename;
- //Move the uploaded file to temp directory
- $s3 = AWS::get('s3');
- $upload_success = $s3->putObject([
- 'ACL' => 'public-read',
- 'Bucket' => 'cbdevs3',
- 'Key' => $directory,
- 'ContentType' => 'image/'.$extension,
- 'Body' => fopen($image->getPathname(), 'r'), ]);
- return $upload_success ? $filename :'';
- }
- else
- return '';
- }return '';
- }
- }
Add Comment
Please, Sign In to add comment