sheena2994

Untitled

Feb 21st, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // uploading image to s3 from public folder
  2.  
  3. use Aws\S3\S3Client;
  4. use AwsS3S3Client;
  5.  
  6.  
  7. $filename='group_image'.$group_id.'.jpg';
  8.  
  9. // save image in output Buffer --
  10. ob_start();
  11. imagejpeg($outputImage,NULL,100);
  12. $imageFileContents = ob_get_contents();
  13.  
  14. // header('Content-Type: image/png');
  15. // imagepng($imageFileContents);
  16.  
  17. // use AwsS3S3Client;
  18. $directory = 'uploads/images/'.$filename;
  19.  
  20. // Create an Amazon S3 client object
  21. $client = S3Client::factory(array(
  22.  
  23. 'secret' => 'RtzcCuO2yLnHWtFpjcpNaPHdFKhI4QfaICSngw4q',
  24. 'key' => 'AKIAJAJRA6ZVHKUBHW7A'
  25. ));
  26.  
  27.  
  28. $context = stream_context_create(array(
  29.  
  30. 's3' => array(
  31. 'ACL' => 'public-read'
  32. )
  33. ));
  34.  
  35. // Register the stream wrapper from a client object
  36. $client->registerStreamWrapper();
  37.  
  38. $bucket = 'momentsbucket';
  39. $key = $directory;
  40.  
  41. // save content on S3 --
  42. $contents = file_put_contents("s3://{$bucket}/{$key}",$imageFileContents,0,$context);
  43.  
  44. $size = filesize("s3://{$bucket}/{$key}");
  45.  
  46. ob_end_clean(); // clear o/p buffer
Add Comment
Please, Sign In to add comment