示例#1
1
 public function atualizarfotoAction()
 {
     General::permissaoAuth(false);
     $nu_imagem = uniqid();
     if ($_FILES['Filedata']) {
         $tmpPath = APPLICATION_PATH . "/../data/tmp/";
         $finfo = pathinfo($_FILES['Filedata']['name']);
         $name = $nu_imagem . '.' . $finfo['extension'];
         if (!in_array(strtolower($finfo['extension']), array('jpg', 'png', 'jpeg'))) {
             echo json_encode(array('status' => 0, 'msg' => _("Extensão não permitida!")));
             die;
         }
         @move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpPath . $name);
         try {
             copy($tmpPath . $name, $tmpPath . "128_" . $name);
             $canvas = canvas::Instance($tmpPath . "128_" . $name);
             $canvas->redimensiona(128, 128, 'crop');
             $canvas->grava($tmpPath . "128_" . $name, 90);
             copy($tmpPath . $name, $tmpPath . "70_" . $name);
             $canvas = canvas::Instance();
             $canvas->carrega($tmpPath . "70_" . $name);
             $canvas->redimensiona(70, 70, 'crop');
             $canvas->grava($tmpPath . "70_" . $name, 90);
             copy($tmpPath . $name, $tmpPath . "50_" . $name);
             $canvas = canvas::Instance();
             $canvas->carrega($tmpPath . "50_" . $name);
             $canvas->redimensiona(50, 50, 'crop');
             $canvas->grava($tmpPath . "50_" . $name, 90);
             copy($tmpPath . $name, $tmpPath . "32_" . $name);
             $canvas = canvas::Instance();
             $canvas->carrega($tmpPath . "32_" . $name);
             $canvas->redimensiona(32, 32, 'crop');
             $canvas->grava($tmpPath . "32_" . $name, 90);
             @unlink($tmpPath . $name);
         } catch (Exception $e) {
             echo json_encode(array('status' => 0, 'msg' => 'Error!'));
             @unlink($tmpPath . "32_" . $name);
             @unlink($tmpPath . "50_" . $name);
             @unlink($tmpPath . "70_" . $name);
             @unlink($tmpPath . "128_" . $name);
         }
         try {
             Model_Usuario::getInstance()->cadastrarFoto(array('nu_imagem' => $nu_imagem));
             $s3 = new S3(Zend_Registry::get('application')->sys->aws_accesskey, Zend_Registry::get('application')->sys->aws_secretkey);
             $bucket = Zend_Registry::get('application')->sys->aws_s3_bucket;
             $s3->putObjectFile($tmpPath . "32_" . $name, $bucket, "32_" . $name, S3::ACL_PUBLIC_READ);
             $s3->putObjectFile($tmpPath . "50_" . $name, $bucket, "50_" . $name, S3::ACL_PUBLIC_READ);
             $s3->putObjectFile($tmpPath . "70_" . $name, $bucket, "70_" . $name, S3::ACL_PUBLIC_READ);
             $s3->putObjectFile($tmpPath . "128_" . $name, $bucket, "128_" . $name, S3::ACL_PUBLIC_READ);
             @unlink($tmpPath . "32_" . $name);
             @unlink($tmpPath . "50_" . $name);
             @unlink($tmpPath . "70_" . $name);
             @unlink($tmpPath . "128_" . $name);
         } catch (Exception $e) {
             echo json_encode(array('status' => 0, 'msg' => _("Erro ao processar as imagens")));
             @unlink($tmpPath . "32_" . $name);
             @unlink($tmpPath . "50_" . $name);
             @unlink($tmpPath . "70_" . $name);
             @unlink($tmpPath . "128_" . $name);
         }
         $_SESSION['tw_auth']['nu_imagem'] = $nu_imagem;
         $url_imagem = General::urlImgUser(array('nu_imagem' => $nu_imagem, 'size' => 50));
         echo json_encode(array('status' => 1, 'msg' => 'success', 'nu_imagem' => $nu_imagem, 'url_imagem' => $url_imagem));
     }
 }