Upload resized image on amazon S3 with PHP SDK -


i have script wich resize , crop image , upload image on amazon s3 on fly.

the problem error message when try run script because guess sourcefile not recognized direct path disk ($filepath). have idea through situation?

fatal error: uncaught exception 'aws\common\exception\invalidargumentexception' message 'you must specify non-null value body or sourcefile parameters.' in phar:///var/www/submit/aws.phar/aws/common/client/uploadbodylistener.php:...

$myresizedimage = imagecreatetruecolor($width,$height);         imagecopyresampled($myresizedimage,$myimage,0,0,0,0, $width, $height, $originewidth, $origineheight);  $myimagecrop = imagecreatetruecolor(612,612);         imagecopy( $myimagecrop, $myresizedimage, 0,0, $posx, $posy, 612, 612);  //save image on amazon s3       require 'aws.phar';  use aws\s3\s3client; use aws\s3\exception\s3exception;  $bucket = 'yol'; $keyname = 'image_resized';                     $filepath = $myimagecrop;  // instantiate client. $s3 = s3client::factory(array(     'key'    => 'private-key',     'secret' => 'secrete-key',     'region' => 'eu-west-1'      ));  try {     // upload data.     $result = $s3->putobject(array(         'bucket' => $bucket,         'key'    => $keyname,         'sourcefile'   => $filepath,         'acl'    => 'public-read',         'contenttype' => 'image/jpeg'     ));      // print url object.     echo $result['objecturl'] . "\n"; } catch (s3exception $e) {     echo $e->getmessage() . "\n"; } 

you setting sourcefile of upload $filepath, assigned $myimagecrop = imagecreatetruecolor(...). such, it's not path @ — it's gd image resource. can't upload these s3 directly.

you'll need either write image out file (using e.g. imagejpeg() + file_put_contents()), or run upload using data in memory (again, imagejpeg() or similar).


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -