/**
  * Main method for downloading image by $imageUrl and save it to the directory $dir
  *
  * @param $imageUrl
  * @param $dir
  * @return int - file size in bytes
  * @throws \Exception
  */
 public function download($imageUrl, $dir)
 {
     $imageInstance = $this->createImageInstance($imageUrl);
     if (!$imageInstance->getFileExists()) {
         throw new \Exception('File not exists!');
     }
     $imageValidator = new ImageValidator(['jpg', 'png', 'gif']);
     if (!$imageValidator->validate($imageInstance)) {
         throw new \Exception('Not allowed file format!');
     }
     $imageSaver = $this->createImageSaver($dir);
     return $imageSaver->save($imageInstance);
 }
 /**
  * setAllowedImageExtensions
  * @param array $arrAllowedImageExtensions
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function setAllowedImageExtensions($arrAllowedImageExtensions)
 {
     $this->core->logger->debug('massiveart.validators.ImageValidator.setAllowedImageExtensions()');
     self::$arrAllowedImageExtensions = $arrAllowedImageExtensions;
     $this->core->logger->debug(self::$arrAllowedImageExtensions);
 }
Example #3
0
 public function actionEditAvatar()
 {
     $uri = trim($_SERVER['REQUEST_URI'], '/');
     $userId = User::checkLogged()['id'];
     $filePath = $_SERVER['DOCUMENT_ROOT'] . '/public/images/users/avatars/' . $userId . '.jpg';
     $result = false;
     if (isset($_POST['submit'])) {
         if (is_uploaded_file($_FILES['avatar']['tmp_name'])) {
             $errors = false;
             if (!ImageValidator::сheckSize()) {
                 $errors[] = 'Слишком большой размер файла';
             }
             if (!ImageValidator::сheckType()) {
                 $errors[] = 'Тип картинки может быть только .jpg';
             }
             if ($errors == false) {
                 move_uploaded_file($_FILES['avatar']['tmp_name'], $filePath);
                 if (isset($_POST['rotate'])) {
                     User::imageRotate($filePath, $_POST['rotate']);
                 }
                 if (isset($_POST['grayscale'])) {
                     User::imageGray($filePath, $_POST['rotate']);
                 }
                 $result = true;
                 // header("Location: /");
             }
         }
     }
     require_once ROOT . '/views/user/edit_avatar.php';
 }