Exemplo n.º 1
0
 public function actionPhotosendproc()
 {
     if (isset($_REQUEST["idPerson"])) {
         try {
             $model = Person::model()->find("idPerson = " . $_REQUEST["idPerson"]);
             $path = Yii::app()->basePath . "/.." . Yii::app()->params['photosBigPath'];
             $id = $model->idPerson;
             $tfio = $model->PhotoName;
             $file = $path . $tfio;
             if (file_exists($file)) {
                 // $data = file_get_contents($file);
                 //$type = pathinfo($file, PATHINFO_EXTENSION);
                 //$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
                 $img = EWideImage::loadFromFile($file);
                 $tmp_name = $path . md5(time()) . ".jpg";
                 $img->resize(255, null)->saveToFile($tmp_name);
                 $data = file_get_contents($tmp_name);
                 $base64 = base64_encode($data);
                 $res = WebServices::updatePersonPhoto($model->codeU, $base64);
                 if (file_exists($tmp_name)) {
                     unlink($tmp_name);
                 }
                 if ($res == 1) {
                     echo $model->codeU . " : ok!";
                 } else {
                     echo $model->codeU . " : error!";
                 }
             } else {
                 echo "Фото відсутне! ({$file})";
             }
         } catch (Exception $ex) {
             if (file_exists($tmp_name)) {
                 unlink($tmp_name);
             }
             echo $ex->getMessage();
         }
     } else {
         echo "Необхыдно вказати ідентифікатор персони.";
     }
 }