Validates image and return true on success and
array of error messages on failure

@param UploadedFile $handle
@return boolean | string
188044
protected function validateImage (UploadedFile $handle)
    {
        $configs = $this->getConfigs();
        $maxSize = $configs['max_upload_size'];
        $extensions = $configs['extensions'];
        $imageConstraint = new Image();
        $imageConstraint->minWidth = $configs['minWidth'];
        $imageConstraint->minHeight = $configs['minHeight'];
        $imageConstraint->maxSize = $maxSize;
        $imageConstraint->mimeTypes =
            array_map(function($item){return 'image/' . $item;}, explode( ',',  $extensions));
        $errors = $this->container->get('validator')->validateValue($handle, $imageConstraint);

        if (count($errors) == 0) {
            return true;
        } else {
            return $this->container->get('translator')
                ->trans(/** @Ignore */$errors[0]->getMessageTemplate(), $errors[0]->getMessageParameters());
        }
    }
494507
public function isValid()
    {
        foreach ($this->objects as $fileInfo) {
            // Before validation callback
            $this->applyCallback('beforeValidation', $fileInfo);

            // Check is uploaded file
            if ($fileInfo->isUploadedFile() === false) {
                $this->errors[] = sprintf(
                    '%s: %s',
                    $fileInfo->getNameWithExtension(),
                    'Is not an uploaded file'
                );
                continue;
            }

            // Apply user validations
            foreach ($this->validations as $validation) {
                try {
                    $validation->validate($fileInfo);
                } catch (\Upload\Exception $e) {
                    $this->errors[] = sprintf(
                        '%s: %s',
                        $fileInfo->getNameWithExtension(),
                        $e->getMessage()
                    );
                }
            }

            // After validation callback
            $this->applyCallback('afterValidation', $fileInfo);
        }

        return empty($this->errors);
    }
259285
public function isValid() {
		
		$params = $this -> getParameters();
		$file 	= $this -> getFile();

		if(false === isset($params[0])) {
			return trigger_error(sprintf('Missing argument 1 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === ('-' . intval($params[0]) == '-' . $params[0])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($params[0])), E_USER_ERROR);
		}

		$dimensions = @getimagesize($file['tmp_name']);

		if(true === is_array($dimensions)) {

			if($dimensions[0] >= $params[0]) {
				return true;
			}
		}

		return false;
	}
417920
public function validateUpload()
    {
        \Message::reset();
        $strTempName = $this->strName . '_fineuploader';
        $objUploader = new \Haste\Util\FileUpload($this->strName);
        $blnIsChunk = isset($_POST['qqpartindex']);

        // Convert the $_FILES array to Contao format
        if (!empty($_FILES[$strTempName])) {
            $arrFile = array
            (
                'name' => array($_FILES[$strTempName]['name']),
                'type' => array($_FILES[$strTempName]['type']),
                'tmp_name' => array($_FILES[$strTempName]['tmp_name']),
                'error' => array($_FILES[$strTempName]['error']),
                'size' => array($_FILES[$strTempName]['size']),
            );

            // Replace the comma character (#22)
            $arrFile['name'] = str_replace(',', '_', $arrFile['name']);

            // Set the UUID as the filename
            if ($blnIsChunk) {
                $arrFile['name'][0] = \Input::post('qquuid') . '.chunk';
            }

            // Check if the file exists
            if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) {
                $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath);
            }

            $_FILES[$this->strName] = $arrFile;
            unset($_FILES[$strTempName]); // Unset the temporary file
        }

        $varInput = '';

        // Add the "chunk" extension to upload types
        if ($blnIsChunk) {
            $extensions   = trimsplit(',', $GLOBALS['TL_CONFIG']['uploadTypes']);
            $extensions[] = 'chunk';

            $objUploader->setExtensions($extensions);
        }

        // Validate the minlength
        if ($this->arrConfiguration['minlength'] > 0 && !$blnIsChunk) {
            $objUploader->setMinFileSize($this->arrConfiguration['minlength']);
        }

        // Validate the maxlength
        if ($this->arrConfiguration['maxlength'] > 0 || $blnIsChunk) {
            $objUploader->setMaxFileSize($blnIsChunk ? $this->arrConfiguration['chunkSize'] : $this->arrConfiguration['maxlength']);
        }

        // Set the maximum width
        if ($this->arrConfiguration['maxWidth']) {
            $objUploader->setImageWidth($this->arrConfiguration['maxWidth']);
        }

        // Set the maximum height
        if ($this->arrConfiguration['maxHeight']) {
            $objUploader->setImageHeight($this->arrConfiguration['maxHeight']);
        }

        try {
            $varInput = $objUploader->uploadTo($this->strTemporaryPath);

            if ($objUploader->hasError()) {
                if (version_compare(VERSION, '4.2', '>=')) {
                    $session = \System::getContainer()->get('session');

                    foreach ($session->getFlashBag()->peek('contao.'.TL_MODE.'.error') as $strError) {
                        $this->addError($strError);
                    }
                } else {
                    foreach ((array) $_SESSION['TL_ERROR'] as $strError) {
                        $this->addError($strError);
                    }
                }
            }

            \Message::reset();
        } catch (\Exception $e) {
            $this->addError($e->getMessage());
        }

        if (!is_array($varInput) || empty($varInput)) {
            $this->addError($GLOBALS['TL_LANG']['MSC']['fineuploader_error']);
        }

        $varInput = $varInput[0];

        // Store the chunk in the session for further merge
        if ($blnIsChunk) {
            $_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')][] = $varInput;

            // This is the last chunking request, merge the chunks and create the final file
            if (\Input::post('qqpartindex') == \Input::post('qqtotalparts') - 1) {
                $strFileName = \Input::post('qqfilename');

                // Get the new file name
                if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $strFileName)) {
                    $strFileName = $this->getFileName($strFileName, $this->strTemporaryPath);
                }

                $objFile = new \File($this->strTemporaryPath . '/' . $strFileName);

                // Merge the chunks
                foreach ($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')] as $strChunk) {
                    $objFile->append(file_get_contents(TL_ROOT . '/' . $strChunk), '');

                    // Delete the file
                    \Files::getInstance()->delete($strChunk);
                }

                $objFile->close();
                $varInput = $objFile->path;

                // Validate the minlength
                if ($this->arrConfiguration['minlength'] > 0 && $objFile->size < $this->arrConfiguration['minlength']) {
                    $readableSize = \System::getReadableSize($this->arrConfiguration['minlength']);
                    $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['minFileSize'], $readableSize));
                    \System::log('File "'.$objFile->name.'" is smaller than the minimum file size of '.$readableSize, __METHOD__, TL_ERROR);
                }

                // Validate the maxlength
                if ($this->arrConfiguration['maxlength'] > 0 && $objFile->size > $this->arrConfiguration['maxlength']) {
                    $readableSize = \System::getReadableSize($this->arrConfiguration['maxlength']);
                    $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['maxFileSize'], $readableSize));
                    \System::log('File "'.$objFile->name.'" exceeds the maximum file size of '.$readableSize, __METHOD__, TL_ERROR);
                }

                // Reset the chunk flag
                $blnIsChunk = false;

                // Unset the file session after merging the chunks
                unset($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')]);
            }
        }

        // Validate and move the file immediately
        if ($this->arrConfiguration['directUpload'] && !$blnIsChunk) {
            $varInput = $this->validatorSingle($varInput, $this->getDestinationFolder());
        }

        return $varInput;
    }
576951
public function validateArguments($methods, $handler): array
    {
        if (!$methods || !$handler) {
            throw new \InvalidArgumentException('The method and route handler is not allow empty.');
        }

        $allow = self::ALLOWED_METHODS_STR . ',';
        $hasAny = false;

        $methods = \array_map(function ($m) use ($allow, &$hasAny) {
            $m = \strtoupper(trim($m));

            if (!$m || false === \strpos($allow, $m . ',')) {
                throw new \InvalidArgumentException("The method [$m] is not supported, Allow: " . trim($allow, ','));
            }

            if (!$hasAny && $m === self::ANY) {
                $hasAny = true;
            }

            return $m;
        }, (array)$methods);

        return $hasAny ? self::ALLOWED_METHODS : $methods;
    }
1331272
private function _getProviderRecordByHandle($handle)
    {
        $providerRecord = Oauth_ProviderInfosRecord::model()->find(

            // conditions
            'class=:provider',

            // params
            array(
                ':provider' => $handle
            )
        );

        if($providerRecord)
        {
            return $providerRecord;
        }

        return null;
    }
541366
protected function prepareForeach(UploadedFile $image = null)
    {
        $self       = clone $this;
        $self->name = $self->getStoreName($image);

        $self->callInterventionMethods($image->getRealPath());

        return tap($self->upload($image), function () use ($self) {
            $self->name = null;
        });
    }
1266854
public function readByHandle($handle)
    {
        $service = $this->getService();

        $response      = $service->request('products/handle/' . $handle, 'GET');
        $responseArray = $this->getResponseArray($response);

        if (!$this->isError()) {
            $this->_data = $responseArray['product'];
        } else {
            $this->_data = array();
        }

        return $this;
    }
147844
public static function in($object, array $handle): bool
    {
        if (!Any::isLine($object)) {
            return false;
        }

        // allow empty, validate on required rule
        if (Any::isEmpty($object)) {
            return true;
        }

        $object = Any::guessValueType($object);

        $res = Arr::in($object, $handle);
        return $res;
    }
211426
public function findRequest($handle) {
        foreach($this->requests as $request) {
            if($handle === $request->getHandle()) {
                return $request;
            }
        }

        return false;
    }
1041038
final protected function validateFile () : bool
	{
		$file = $this->file;
		// Perform error checking on the file parameter parsed in
		if (!$file || empty($file) || !is_array($file)):
			// Error: nothing uploaded or wrong argument usage
			$this->error = "No file was uploaded.";
			return FALSE;
		endif;
		// Check if file is not empty
		if (!isset($file) || !is_uploaded_file($file['tmp_name'])):
			// Error: in file upload
			$this->error = "Uploaded file is Missing.";
			return FALSE;
		endif;
		// Check if file doesn't contain any error
		if ($file['error'] != 0):
			// Error: report what php says went wrong
			$this->error = $this->fileUploadErrors[$file['error']];
			return FALSE;
		endif;
		return TRUE;
	}
350349
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        /* @var ValidatorInterface $validator */
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);
        $serviceData    = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA);
        $validator      = App::getBean(ServiceValidator::class);

        list($className, $validatorKey) = $serviceHandler;
        $collector = ValidatorCollector::getCollector();
        if (isset($collector[$className][$validatorKey]['validator'])) {
            $validators = $collector[$className][$validatorKey]['validator'];
            $validator->validate($validators, $serviceHandler, $serviceData);
        }

        return $handler->handle($request);
    }
32703
public function validate(\Upload\File $file) {
        $isValid = true;
        $dimensions = $file->getDimensions();
        $filename = $file->getNameWithExtension();
        if (!$dimensions) {
            $this->setMessage(sprintf('%s: Could not detect image size.', $filename));
            $isValid = false;
        }
        if ($dimensions['width'] != $this->width) {
            $this->setMessage(sprintf('Image width(%dpx) does not match required width(%dpx)', $dimensions['width'], $this->width));
            $isValid = false;
        }
        if ($dimensions['height'] != $this->height) {
            $this->setMessage(sprintf('Image height(%dpx) does not match required height(%dpx)', $dimensions['height'], $this->height));
            $isValid = false;
        }

        return $isValid;
    }
990902
protected function validateImagesStore()
    {
        if ($this->isError()) {
            return null;
        }

        $error = false;

        foreach (array('logo', 'favicon') as $field) {

            if ($this->getSubmitted("delete_$field")) {
                $this->setSubmitted("data.$field", '');
            }

            $file = $this->request->file($field);

            if (empty($file)) {
                continue;
            }

            $result = $this->file_transfer->upload($file, null, 'image/upload/store');

            if ($result !== true) {
                $error = true;
                $this->setError($field, (string) $result);
                continue;
            }

            $this->setSubmitted("data.$field", $this->file_transfer->getTransferred(true));
        }

        return empty($error);
    }
61384
protected function loadUser($handle)
    {
        if (!$handle) {
            return null;
        }

        // Try to get user by ID
        $user = $this->modelFactory()->create(User::class);
        $user->load($handle);
        if ($user->id() !== null) {
            return $user;
        }

        // Try to get user by email
        $user->loadFrom('email', $handle);
        if ($user->id() !== null) {
            return $user;
        }

        return null;
    }
549418
public function ValidateUpload($InputName, $ThrowError = TRUE) {
   
      if (!function_exists('gd_info'))
         throw new Exception(T('The uploaded file could not be processed because GD is not installed.'));
   
      // Make sure that all standard file upload checks are performed.
      $TmpFileName = parent::ValidateUpload($InputName, $ThrowError);
      
      // Now perform image-specific checks.
      if ($TmpFileName) {
         $Size = getimagesize($TmpFileName);
         if ($Size === FALSE)
            throw new Exception(T('The uploaded file was not an image.'));
      }
      
      return $TmpFileName;
   }
163822
function loadfile($handle)
    {
        // If the file for this handle is already loaded and compiled, do nothing.
        if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle])) {
            return true;
        }

        // If we don't have a file assigned to this handle, die.
        if (!isset($this->files[$handle])) {
            die("Template->loadfile(): Aucun fichier spécifié pour le modèle". $handle);
        }

        $filename = $this->files[$handle];

        $str = implode("", @file($filename)); 
        if (empty($str)) {
            die("Template->loadfile(): Le fichier $filename pour le modèle $handle est vide");
        }

        $this->uncompiled_code[$handle] = $str;

        return true;
    }