代码点火器和S3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码点火器和S3相关的知识,希望对你有一定的参考价值。

  1. public function batchUploadS3($files, $bucket, $bucketPath = '')
  2. {
  3. // Now we should push these off to S3
  4. // Include the SDK
  5. require_once(APPPATH . "/libraries/amazon_sdk/sdk.class.php");
  6.  
  7. $s3 = new AmazonS3();
  8.  
  9. // Prepare to hold the individual filenames
  10. $individual_filenames = array();
  11.  
  12. // Loop over the list, referring to a single file at a time
  13. foreach ($files as $id=>$file)
  14. {
  15. // Grab only the filename part of the path
  16. $fileParts = pathinfo($file);
  17. $filename = $bucketPath.'/'.$fileParts['basename'];
  18.  
  19. // Store the filename for later use
  20. $individual_filenames[$id] = $filename;
  21.  
  22. /* Prepare to upload the file to our new S3 bucket. Add this
  23.   request to a queue that we won't execute quite yet. */
  24. $s3->batch()->create_object($bucket, $filename, array(
  25. 'fileUpload' => $file,
  26. 'acl' => AmazonS3::ACL_PUBLIC
  27. ));
  28. }
  29.  
  30. /* Execute our queue of batched requests. This may take a few seconds to a
  31.   few minutes depending on the size of the files and how fast your upload
  32.   speeds are. */
  33. $file_upload_response = $s3->batch()->send();
  34.  
  35. /* Since a batch of requests will return multiple responses, let's
  36.   make sure they ALL came back successfully using `areOK()` (singular
  37.   responses use `isOK()`). */
  38. if ($file_upload_response->areOK())
  39. {
  40. // Loop through the individual filenames
  41. foreach ($individual_filenames as $id=>$filename)
  42. {
  43. /* Display a URL for each of the files we uploaded. Since uploads default to
  44.   private (you can choose to override this setting when uploading), we'll
  45.   pre-authenticate the file URL for the next 5 minutes. */
  46. $files[$id] = $s3->get_object_url($bucket, $filename);
  47. }
  48. }else{
  49. error_log("batchUploadS3 failed");
  50. }
  51.  
  52. return $files;
  53. }

以上是关于代码点火器和S3的主要内容,如果未能解决你的问题,请参考以下文章

使用代码点火器和 gmail smtp 从本地主机上的 xampp 发送电子邮件

代码点火器错误“地址不被理解”

代码点火器 + CSS

如何制作前端 Gallery.view 代码点火器

使用 .html 页面视图而不是 .php?代码点火器

在 Cpanel 中设置两个代码点火器应用程序