Ankit_pastebin

Untitled

Feb 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. // Image uploading to using S3 --
  2. public static function imageUploading($image){
  3.  
  4. if(isset($image)){
  5.  
  6. if($image->isValid()){ //Determining If An Uploaded File Is Valid
  7.  
  8. //Retrieving The Extension Of An Uploaded File
  9. $extension = $image->getClientOriginalExtension();
  10.  
  11. //change filename to a random sha1 plus current time
  12. $filename = "img_" . substr(sha1(time().time()), 0, 15) .".{$extension}";
  13.  
  14. //define directory to store images
  15. $directory = 'uploads/images/'.$filename;
  16.  
  17. //Move the uploaded file to temp directory
  18. $s3 = AWS::get('s3');
  19.  
  20. $upload_success = $s3->putObject([
  21. 'ACL' => 'public-read',
  22. 'Bucket' => 'cbdevs3',
  23. 'Key' => $directory,
  24. 'ContentType' => 'image/'.$extension,
  25. 'Body' => fopen($image->getPathname(), 'r'), ]);
  26.  
  27. return $upload_success ? $filename :'';
  28. }
  29. else
  30. return '';
  31. }return '';
  32. }
  33.  
  34.  
  35. }
Add Comment
Please, Sign In to add comment