Ejemplo n.º 1
0
 public function actionImageurl()
 {
     if (isset($_GET['url'])) {
         $ext = substr($_GET['url'], -4);
         if (!in_array($ext, array('.jpg', '.png', '.gif', '.JPG', '.PNG', '.GIF'))) {
             echo 'Wrong url!.';
             return;
         }
         $name = end(explode("/", $_GET['url']));
         $sourcecode = Helper::GetImageFromUrl($_GET['url']);
         if (isset($_GET['user_id'])) {
             $user_id_image = $_GET['user_id'];
         } else {
             $user_id_image = Yii::app()->user->id;
         }
         $media = new Medias();
         $fileName = $media->getImageName($name);
         //check image file
         $checkImage = $media->saveImageUrl($fileName, $sourcecode, $user_id_image);
         if ($checkImage == null) {
             echo '<div class="errorMessage">Invalid url!</div>';
             return;
         }
         $media->url = $fileName;
         $media->type = 'image-upload';
         $media->title = substr($fileName, 25);
         if ($media->save()) {
             $this->layout = "";
             $this->render('imageupload', array('model' => $media));
         } else {
             echo '<div class="errorMessage">Not save!</div>';
         }
     }
     return;
 }