jeudi 15 octobre 2015

upload image in amazon S3 after re-sizing it in Yii2

I want to upload RESIZED image in Amazon S3. I have uploaded original image. But now also want to create thumb and upload it.

Here is my code to upload original image:

    <?php
    $bucket = 'abc';
    $bucket = NEST_BUCKET_ORIGINAL;    
    if($s3->putObject($_FILES['pic']['tmp_name'], $bucket, $newfilename, S3::ACL_PUBLIC_READ) )
    {
        $key = "thumb/{$newfilename}";
        $s3file = 'http://'.$bucket.'.PATH/'.$newfilename;
        $collection = \Yii::$app->mongodb->getCollection('nest');
        $set = array('pic'=>$newfilename);
        $where = array('_id'=>$i);
        $collection->update($where,$set);
        $thumbFile = $_FILES["pic"]["name"];
        $targetpath = 'http://'.$bucket.'.PATH/'.$newfilename;
        Image::thumbnail($_FILES['pic']['tmp_name'], $w, $h)->save($key, ['quality' => 80]);
    }
    ?>




Aucun commentaire:

Enregistrer un commentaire