Code posted by: elf on 2013-05-02 15:43:56 GMT+10 - type PHP
  1. <?php
  2. require_once 'AWSSDKforPHP/sdk.class.php';
  3. require_once 'config.inc.php';
  4.  
  5. function microtime_float()
  6. {
  7.     list($usec, $sec) = explode(" ", microtime());
  8.     return ((float)$usec + (float)$sec);
  9. }
  10.  
  11. $bucket = 'mybucket';
  12.  
  13. define('MB', 1048576);
  14. $s3 = new AmazonS3();
  15. $s3->disable_ssl(); //because I don't care about SSL right now ;)
  16.  
  17. $dir = '/home/myfolder/files';
  18. $dh = opendir($dir);
  19. while (false !== ($filename = readdir($dh)))
  20. {
  21.         $files[] = $filename;
  22. }
  23. sort ($files);
  24. print_r($files);
  25. foreach($files as $filename)
  26. {
  27.         //lets upload a bunch of .tar.gz archives only
  28.         if (strstr($filename, '.tar.gz'))
  29.         {
  30.  
  31.                 $filepath = $dir.'/'.$filename;
  32.                 $keyname = date('Y-m', time()).'/'.$filename;
  33.                 //creating a new subfolder in our bucket based on the date... this script is a monthly backup script.
  34.                 $exists = $s3->if_object_exists($bucket, $keyname);
  35.                 if (!$exists)
  36.                 {
  37.                         $time_start = microtime_float();
  38.                         echo "attempting to upload $filepath\n";
  39.                         $response = $s3->create_mpu_object($bucket, $keyname, array(
  40.                                 'fileUpload' => $filepath,
  41.                                 'partSize' => 100*MB,
  42.                                 'storage' => AmazonS3::STORAGE_REDUCED
  43.                         ));
  44.                        
  45.                         //output how long it took to upload the file
  46.                         $time_end = microtime_float();
  47.                         $time = $time_end - $time_start;
  48.                         echo "Upload completed in $time seconds!\n";
  49.                         flush();
  50.                 }
  51.         }
  52.  
  53. }
  54.  
  55. ?>
  56.  

New post:
Respond to the original code above (post ID uicn4rf)? Yes (click here to paste the code from above), or click here to make a new post.

Syntax highlighting?
Name (blank for Anonymous)
How long to keep it for?
 
Type the above security code:


© 2006-2008 CreatioNova.com and CreationExchange.com.
Site design and code mostly developed by elf (with the exception of GeSHi of course).
Hits: 60422