title: Integrating JqueryUpload plugin with AWS php sdk to upload images to S3
body: <p>I am working on the integration of jqueryfileupload plugin with AWS.I have completed the upload section successfully,but now i am looking to integrate the image resize feature.<br/>
  I am using <a href="https://github.com/blueimp/jQuery-File-Upload#download" rel="nofollow">this</a> plugin code.I have set up an example using minimum code which is as below.<br/></p>
  
  <p><strong>index.html</strong></p>
  
  <pre><code> &lt;!DOCTYPE HTML&gt;
   &lt;html&gt;
   &lt;head&gt;
   &lt;meta charset="utf-8"&gt;
   &lt;title&gt;jQuery File Upload Example&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
   &lt;input id="fileupload" type="file" name="files[]" data-url="aws/" multiple&gt;
   &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
   &lt;script src="js/vendor/jquery.ui.widget.js"&gt;&lt;/script&gt;
   &lt;script src="js/jquery.iframe-transport.js"&gt;&lt;/script&gt;
   &lt;script src="js/jquery.fileupload.js"&gt;&lt;/script&gt;
   &lt;script&gt;
     $(function () {
       $('#fileupload').fileupload({
        dataType: 'json',
        done: function (e, data) {
          $.each(data.result.files, function (index, file) {
              $('&lt;p/&gt;').text(file.name).appendTo(document.body);
          });
        }
      });
    });
     &lt;/script&gt;
    &lt;/body&gt; 
   &lt;/html&gt;
  </code></pre>
  
  <p><strong>awssdk.php</strong>---This is the file I call after image is selected.</p>
  
  <pre><code>      &lt;?php 
      $bucket = "my bucket name";
      $subFolder = "";  // leave blank for upload into the bucket directly
      if (!class_exists('S3'))require_once('S3.php');
  
      //AWS access info
     if (!defined('awsAccessKey')) define('awsAccessKey', 'my key');
     if (!defined('awsSecretKey')) define('awsSecretKey', 'my secret key');
  
  
      $options = array( 'image_versions' =&gt; array(
       'small' =&gt; array(
      'max_width' =&gt; 1920,
      'max_height' =&gt; 1200,
      'jpeg_quality' =&gt; 95
   ),
  
  'medium' =&gt; array(
      'max_width' =&gt; 800,
      'max_height' =&gt; 600,
      'jpeg_quality' =&gt; 80
  ),
  
  'thumbnail' =&gt; array(
      'max_width' =&gt; 80,
      'max_height' =&gt; 80
  )
     ) 
    );
  
    //instantiate the class
    $s3 = new S3(awsAccessKey, awsSecretKey);
  
    function getFileInfo($bucket, $fileName) {
     global $s3;
     $fileArray = "";
     $size = $s3-&gt;getBucket($bucket);
     $furl = "http://" . $bucket . ".s3.amazonaws.com/".$fileName;
     $fileArray['name'] = $fileName;
     $fileArray['size'] = $size;
     $fileArray['url'] = $furl;
     $fileArray['thumbnail'] = $furl;
     $fileArray['delete_url'] = "server/php/index.php?file=".$fileName;
     $fileArray['delete_type'] = "DELETE";
     return $fileArray;
   }
  
    function uploadFiles($bucket, $prefix="") {
     global $s3;
     if (isset($_REQUEST['_method']) &amp;&amp; $_REQUEST['_method'] === 'DELETE') {
       return "";
    }
    $upload = isset($_FILES['files']) ? $_FILES['files'] : null;
    $info = array();
    if ($upload &amp;&amp; is_array($upload['tmp_name'])) {
  foreach($upload['tmp_name'] as $index =&gt; $value) {
      $fileTempName = $upload['tmp_name'][$index];
      $fileName = (isset($_SERVER['HTTP_X_FILE_NAME']) ?      $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index]);
      $fileName = $prefix.str_replace(" ", "_", $fileName);
      // $response = $s3-&gt;create_object($bucket, $fileName, array('fileUpload' =&gt; $fileTempName, 'acl' =&gt; AmazonS3::ACL_PUBLIC, 'meta' =&gt; array('keywords' =&gt; 'example, test'),));
      $response = $s3-&gt;putObjectFile($fileTempName,$bucket,'images/'.$fileName,S3::ACL_PUBLIC_READ);
      //print_r($response);
      if ($response==1) {
          $info[] = getFileInfo($bucket, $fileName);
      } else {
               echo "&lt;strong&gt;Something went wrong while uploading your file... sorry.&lt;/strong&gt;";
      }
  }
  } else {
      if ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) {
          $fileTempName = $upload['tmp_name'];
          $fileName = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name']);
          $fileName =  $prefix.str_replace(" ", "_", $fileName);
          //$response = $s3-&gt;create_object($bucket, $fileName, array('fileUpload' =&gt; $fileTempName, 'acl' =&gt; AmazonS3::ACL_PUBLIC, 'meta' =&gt; array('keywords' =&gt; 'example, test'),));
          $response = $s3-&gt;putObjectFile($upload['tmp_name'],$bucket,$fileName,S3::ACL_PUBLIC_READ);
          if ($response-&gt;isOK()) {
              $info[] = getFileInfo($bucket, $fileName);
          } else {
                   echo "&lt;strong&gt;Something went wrong while uploading your file... sorry.&lt;/strong&gt;";
          }
      }
  }
  header('Vary: Accept');
  $json = json_encode($info);
  $redirect = isset($_REQUEST['redirect']) ? stripslashes($_REQUEST['redirect']) : null;
  if ($redirect) {
      header('Location: ' . sprintf($redirect, rawurlencode($json)));
      return;
  }
  if (isset($_SERVER['HTTP_ACCEPT']) &amp;&amp; (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
      header('Content-type: application/json');
  } else {
      header('Content-type: text/plain');
  }
   return $info;
   }
  ?&gt;
  </code></pre>
  
  <p><a href="https://github.com/tpyo/amazon-s3-php-class/blob/master/S3.php" rel="nofollow">Here</a> is the S3 class I am using.<br/></p>
  
  <p>The JqueryUploadPLugin ships with a server side PHP class to upload images which is great.But as I am using AWS I have to use their API to upload images and the plugin code won't work.As I mentioned above I have implemented the upload portion,but need help to create image thumbnails and different size images before I upload.i.e I want images to upload in 3 variations <code>ex: original,1024x768,100x100</code>.<br/>
  The <a href="https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php" rel="nofollow">UploadHandler.php</a> has few functions for creating scaled images example:<code>protected function create_scaled_image($file_name, $version, $options)</code> for scaling and others. I am stuck at integrating these functions as I am new to OO php and AWS.<br/>Any one done something similar and can give inputs would be helpful<br/>
  Thank you</p>