sheena2994

Untitled

Feb 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1.  
  2. //store file input in a varaible
  3. $file = Input::file('videos');
  4.  
  5. //Retrieving The Extension Of An Uploaded File
  6. $extension = $file->getClientOriginalExtension();
  7.  
  8. //define directory to store images
  9. $directory = '/uploads/videos/';
  10. $dire = public_path().'/uploads/images';
  11.  
  12. //change filename to a random sha1 plus current time
  13. $filename = "video_" . substr(sha1(time().time()), 0, 15) . mt_rand(5, 10) . ".{$extension}";
  14. $thumb = "img_" . mt_rand(1, 99999999) . ".png";
  15.  
  16. $c = exec("ffmpeg -ss 00:00:05 -i ".$file." -vf 'select=not(mod(n\,1000)),scale=320:240' ".$dire.'/'.$thumb);
  17.  
  18. //Move the uploaded file to temp directory
  19. $s3 = AWS::get('s3');
  20. $upload_success = $s3->putObject([
  21. 'ACL' => 'public-read',
  22. 'Bucket' => 'luzapp',
  23. 'Key' => $directory.$filename,
  24. 'Body' => fopen($file->getPathname(), 'r'),
  25. 'ContentType' => 'video/mp4'
  26. ]);
  27.  
  28.  
  29. /*upload file to s3 from public folder*/
  30.  
  31. $image ='uploads/images/'.$thumb;
  32. $outputImage = imagecreatefrompng($image);
  33. // save image in output Buffer --
  34. ob_start();
  35. imagejpeg($outputImage,NULL,100);
  36. $imageFileContents = ob_get_contents();
  37.  
  38. // header('Content-Type: image/png');
  39. // imagepng($imageFileContents);
  40.  
  41. // use AwsS3S3Client;
  42. $directory1 = 'uploads/images/'.$thumb;
  43.  
  44. // Create an Amazon S3 client object
  45. $client = S3Client::factory(array(
  46. 'secret' => 'C/uZfMI+aAG/oeJ0h/wOFTYohmGCMW/WVL9Bq6E3',
  47. 'key' => 'AKIAIQH4ZKDFCTMPLOVQ'
  48. ));
  49.  
  50. $context = stream_context_create(array(
  51. 's3' => array(
  52. 'ACL' => 'public-read'
  53. )
  54. ));
  55.  
  56. // Register the stream wrapper from a client object
  57. $client->registerStreamWrapper();
  58.  
  59. $bucket = 'luzapp';
  60. $key = $directory1;
  61.  
  62. // save content on S3 --
  63. $contents = file_put_contents("s3://{$bucket}/{$key}",$imageFileContents,0,$context);
  64.  
  65. $size = filesize("s3://{$bucket}/{$key}");
  66.  
  67. ob_end_clean(); // clear o/p buffer
  68.  
  69. /*end of upload file to s3 from public folder*/
Add Comment
Please, Sign In to add comment