Ankit_pastebin

Untitled

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