title: How to put PHP image resource into Amazon Web Services?
body: <p>I am currently building a Zend Framework PHP web service that take an image uploaded from Android phone, resize it, and put it into Amazon Web Services S3.</p>
  
  <p>Here are my codes:</p>
  
  <pre><code>$img = $_FILES['image'];
  
      if(!$img)
      {
          return null;
      }
  
      if((($img['type'] == 'image/gif') ||
              ($img['type'] == 'image/jpeg') ||
              ($img['type'] == 'image/png')) &amp;&amp;
              ($img['size'] &lt; 1048576))
      {
          if($img['error'] &gt;0)
          {
              throw new Exception("image contain error ");
          }
  
  
          $size24 = 24;
  
          //obtain the auth settings
          $bootstrap = $this-&gt;getInvokeArg('bootstrap');
          $awsConfigs = $bootstrap-&gt;getOption('aws');
  
          $s3 = new Zend_Service_Amazon_S3($awsConfigs['appkey'], $awsConfigs['secretkey']);
  
          $bucketName = 'item';
          $folderName = 'image';
  
          $perms = array(
                  Zend_Service_Amazon_S3::S3_ACL_HEADER =&gt;
                  zend_service_amazon_s3::S3_ACL_PUBLIC_READ
          );
  
  
          $name =  $bucketName.'/'. $folderName .'/'. uniqid() .'_'. Zend_Date::now()-&gt;toString('yyyyMMdd');
          $smallPath = $name . '_32.png';
  
  
  
          //resize and upload 24x24 image
          $srcImg = imagecreatefrompng($img['tmp_name']);
          $tmp = imagecreatetruecolor($size24, $size24);
          list($oriWidth, $oriHeight) = getimagesize($img['tmp_name']);
          imagecopyresampled($tmp, $srcImg, 0, 0, 0, 0, $size24, $size24, $oriWidth, $oriHeight);
          //not working
                      imagepng($tmp, "tmp_32.png")
          $smallret = $s3-&gt;putFile("tmp_32.png", $smallPath, $perms);
  
          imagedestroy($tmp);
          imagedestroy($srcImg);
  
      }
      else
      {
          throw new Exception("image size/format not qualified.");
      }
  </code></pre>
  
  <p>I am thinking a way to convert the image resource to stream, so I can use $s3->putFileStream or putObject method, but I can't find a valid way.</p>
  
  <p>Any idea??</p>