Checks if the file passes WordPress upload checks.

@since 1.0.0

@return bool
165501
private function check_if_allowed()
    {
        $check = \wp_check_filetype_and_ext($this->data['tmp_name'], $this->client_name);

        if ($check['type'] !== false) {
            $this->guessed_type = $check['type'];
            $this->guessed_extension = $check['ext'];
        }

        if (($check['type'] === false || $check['ext'] === false)
            && !\current_user_can('unfiltered_upload')
        ) {
            return false;
        }

        $allowed_types = \get_allowed_mime_types();

        return \in_array($this->client_type, $allowed_types);
    }
60886
public function accept()
	{
		if( $this->getInnerIterator()->isDot() )
			return FALSE;
		if( $this->getInnerIterator()->isDir() )
			return FALSE;

		if( $this->stripDotFiles )
		{
			$fileName	= $this->getInnerIterator()->getFilename();
			if( $fileName[0] == "." )
				return FALSE;
		}
		return TRUE;
	}
34573
public function isValid()
    {
        $value = $this->field->getValue();

        // no file uploaded?
        if (!$value || !isset($value['error']) || $value['error'] == UPLOAD_ERR_NO_FILE) {
            $this->setErrorMessage($this->messages['required']);
            // required ?
            return !$this->required;
        }

        // check the uploaded file
        switch ($value['error']) {
            case UPLOAD_ERR_OK:
                break;

            case UPLOAD_ERR_FORM_SIZE:
            case UPLOAD_ERR_INI_SIZE:
                $this->setErrorMessage($this->messages['file_too_big']);
                return false;

            case UPLOAD_ERR_PARTIAL:
                $this->setErrorMessage($this->messages['incomplete']);
                return false;

            case UPLOAD_ERR_NO_TMP_DIR:
            case UPLOAD_ERR_CANT_WRITE:
                $this->setErrorMessage($this->messages['cannot_write']);
                return false;

            case UPLOAD_ERR_EXTENSION:
            default:
                $this->setErrorMessage($this->messages['error']);
                return false;
        }

        /**
         * if here, the file was uploaded.
         * Validate the uploaded file against our settings (blacklist, whitelist, etc)
         */

        // retrieve the extension
        if (!$this->isExtensionAllowed($value['name'])) {
            $this->setErrorMessage(sprintf($this->messages['wrong_extension'], implode(',', $this->allowedExtensions)));
            return false;
        }

        if (!$this->isMimetypeAllowed($value['tmp_name'], $value['type'])) {
            $this->setErrorMessage($this->messages['wrong_type']);
            return false;
        }

        $size = filesize($value['tmp_name']);

        // validate the upload file size
        if ($this->maxFilesize && $size > $this->maxFilesize) {
            $this->setErrorMessage(sprintf($this->messages['file_larger_then'], $this->maxFilesize / 1024));
            return false;
        }
        if ($this->minFilesize && $size < $this->minFilesize) {
            $this->setErrorMessage(sprintf($this->messages['file_smaller_then'], $this->minFilesize / 1024));
            return false;
        }

        // if here, the extension and the mime type are validated! The file is good!
        return true;
    }
1094212
function validate()
    {
        if (count($this->_rules) == 0 && count($this->_formRules) == 0 &&
            $this->isSubmitted()) {
            return (0 == count($this->_errors));
        } elseif (!$this->isSubmitted()) {
            return false;
        }

        include_once('HTML/QuickForm/RuleRegistry.php');
        $registry =& HTML_QuickForm_RuleRegistry::singleton();

        foreach ($this->_rules as $target => $rules) {
            $submitValue = $this->getSubmitValue($target);

            foreach ($rules as $rule) {
                if ((isset($rule['group']) && isset($this->_errors[$rule['group']])) ||
                     isset($this->_errors[$target])) {
                    continue 2;
                }
                // If element is not required and is empty, we shouldn't validate it
                if (!$this->isElementRequired($target)) {
                    if (!isset($submitValue) || '' == $submitValue) {
                        continue 2;
                    // Fix for bug #3501: we shouldn't validate not uploaded files, either.
                    // Unfortunately, we can't just use $element->isUploadedFile() since
                    // the element in question can be buried in group. Thus this hack.
                    } elseif (is_array($submitValue)) {
                        if (false === ($pos = strpos($target, '['))) {
                            $isUpload = !empty($this->_submitFiles[$target]);
                        } else {
                            $base = substr($target, 0, $pos);
                            $idx  = "['" . str_replace(array(']', '['), array('', "']['"), substr($target, $pos + 1, -1)) . "']";
                            eval("\$isUpload = isset(\$this->_submitFiles['{$base}']['name']{$idx});");
                        }
                        if ($isUpload && (!isset($submitValue['error']) || 0 != $submitValue['error'])) {
                            continue 2;
                        }
                    }
                }
                if (isset($rule['dependent']) && is_array($rule['dependent'])) {
                    $values = array($submitValue);
                    foreach ($rule['dependent'] as $elName) {
                        $values[] = $this->getSubmitValue($elName);
                    }
                    $result = $registry->validate($rule['type'], $values, $rule['format'], true);
                } elseif (is_array($submitValue) && !isset($rule['howmany'])) {
                    $result = $registry->validate($rule['type'], $submitValue, $rule['format'], true);
                } else {
                    $result = $registry->validate($rule['type'], $submitValue, $rule['format'], false);
                }

                if (!$result || (!empty($rule['howmany']) && $rule['howmany'] > (int)$result)) {
                    if (isset($rule['group'])) {
                        $this->_errors[$rule['group']] = $rule['message'];
                    } else {
                        $this->_errors[$target] = $rule['message'];
                    }
                }
            }
        }

        // process the global rules now
        foreach ($this->_formRules as $rule) {
            if (true !== ($res = call_user_func($rule, $this->_submitValues, $this->_submitFiles))) {
                if (is_array($res)) {
                    $this->_errors += $res;
                } else {
                    return self::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, 'Form rule callback returned invalid value in HTML_QuickForm::validate()', 'HTML_QuickForm_Error', true);
                }
            }
        }

        return (0 == count($this->_errors));
    }
640207
protected function uploadFile () : bool
	{
		// Determine the destination
		$this->newFileLocation = $this->getUploadDir().$this->uploadFileDir.getConstant('DS', TRUE).$this->newFileName;			  
		// Make sure a file doesn't already exist in the target location
		if (file_exists($this->newFileLocation)):
			$this->error = "The file {$this->newFileLocation} already exists.";
			return FALSE;
		endif;
		// Attempt to move/upload the file 
		if (!move_uploaded_file($this->tempPath, $this->newFileLocation)):
			// File was not moved - failure.
			$this->error = "The file upload failed.";
			return FALSE;
		endif;
		// SUCCESS
		return TRUE;
	}
253370
protected function validateType () : bool
	{
		// Checks if video type is allowed
		if ($this->validateMimeType() == FALSE) return FALSE;
		// Checks if video size is valid for upload
		if ($this->validateFileSize() == FALSE) return FALSE;
		// Finally uplods the file after successful evaluation
		if ($this->uploadFile() == FALSE) return FALSE;

		return TRUE;
	}
1172170
public function uploadCover()
    {
        $cover = $this->getTempCover();
        $file = $_FILES['Filedata'];
        $uploadError = Nip_File_System::instance()->getUploadError($file, $cover->extensions);

        if (!$uploadError) {
            $cover->setResourceFromUpload($file);
            if ($cover->validate()) {
                $cover->resize();
                $cover->save();

                $coverCrop = $this->getTempCover();
                $coverCrop->copyResource($cover);

                $max_width = 600;
                $reductionRatio = 600 / $coverCrop->getWidth();

                $coverCrop->max_width = $max_width;
                $coverCrop->setName('crop-' . $cover->name);
                $coverCrop->resize();
                $coverCrop->save();

                $defaultCover = $this->getNewCover('default');
                $coverCrop->cropWidth = $defaultCover->cropWidth * $reductionRatio;
                $coverCrop->cropHeight = $defaultCover->cropHeight * $reductionRatio;

                return $coverCrop;
            } else {
                $this->errors['upload'] = 'Eroare dimensiuni.';
            }
        } else {
            $this->errors['upload'] = $uploadError;
        }


        return false;
    }
799973
def _upload_check(self, upload_info, resumable=False):
        """"""
        return self._api.upload_check(
            filename=upload_info.name,
            size=upload_info.size,
            hash_=upload_info.hash_info.file,
            folder_key=upload_info.folder_key,
            filedrop_key=upload_info.filedrop_key,
            path=upload_info.path,
            resumable=resumable
        )
695536
public function validateUpload()
    {
        $varInput = parent::validateUpload();

        // Check image size
        if (($arrImageSize = @getimagesize(TL_ROOT . '/' . $varInput)) !== false) {

            // Image exceeds maximum image width
            if ($arrImageSize[0] > $GLOBALS['TL_CONFIG']['imageWidth']) {
                $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filewidth'], '', $GLOBALS['TL_CONFIG']['imageWidth']));
            }

            // Image exceeds maximum image height
            if ($arrImageSize[1] > $GLOBALS['TL_CONFIG']['imageHeight']) {
                $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['fileheight'], '', $GLOBALS['TL_CONFIG']['imageHeight']));
            }
        }

        return $varInput;
    }
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;
	}
750435
public function isChanged(): bool
    {
        $this->changedFiles = [];
        do{
            $readResult = \inotify_read($this->handler);
            if(false === $readResult)
            {
                return $result ?? false;
            }
            foreach($readResult as $item)
            {
                $key = array_search($item['wd'], $this->paths);
                if(false === $key)
                {
                    continue;
                }
                $filePath = File::path($key, $item['name']);
                $filePathIsDir = is_dir($filePath);
                if(!$filePathIsDir)
                {
                    $this->changedFiles[] = $filePath;
                }
                if(Bit::has($item['mask'], IN_CREATE) || Bit::has($item['mask'], IN_MOVED_TO))
                {
                    if($filePathIsDir && !$this->isExclude($filePath))
                    {
                        $this->paths[$filePath] = \inotify_add_watch($this->handler, $filePath, $this->mask);
                    }
                }
            }
            $result = isset($readResult[0]);
        }while(true);
    }
794933
public function isBlogPost()
    {
        $skips = ['404.md', 'front-page.md'];
        if ($this->getExtension() != 'md') {
            return false;
        }
        if (in_array($this->getFilename(), $skips)) {
            return false;
        }
        return true;
    }
77744
public function validate()
    {
        $multipleUploads = false;
        if (strval($this->multiple) != '') {
            $field = str_replace('[]', '', $this->name);
            if (isset($_FILES[$field]['name'][0]) && strlen($_FILES[$field]['name'][0]) > 0) {
                $multipleUploads = true;
            }
        }

        if (!$this->checkValue($multipleUploads)) {
            return false;
        }

        $validator = $this->getValidator();
        $this->callValidator($validator);

        if ($this->customError) {
            return false;
        }

        return true;
    }
1374888
public function isValid()
    {
        /**
         * First, check if the upload is valid or not
         */
        if (!parent::isValid()) {
            return false;
        }

        $value = $this->field->getValue();

        // if here, we know that the field is uploaded.

        // check if it's an image, and get it's size
        $size = @getimagesize($value['tmp_name']);
        if ($size === false) {
            $this->setErrorMessage($this->messages['not_an_image']);
            return false;
        }
        list ($width, $height) = $size;

        /**
         * Validate the aspect ratio.
         */
        if (!$this->validateAspectRatio($width, $height)) {
            return false;
        }


        /**
         * Validate the proportions
         */
        if (!$this->validateSize($width, $height)) {
            return false;
        }

        // if here, everything is ok!
        return true;
    }
71565
public function validate()
    {
        // we don't validate for empty upload fields yet
        if (empty($this->tmpFile['name'])) {
            return true;
        }

        // Check file upload
        if (!$this->isValidUpload()) {
            $this->errors[] = _t('SilverStripe\\Assets\\File.NOVALIDUPLOAD', 'File is not a valid upload');
            return false;
        }

        // Check file isn't empty
        if ($this->isFileEmpty()) {
            $this->errors[] = _t('SilverStripe\\Assets\\File.NOFILESIZE', 'Filesize is zero bytes.');
            return false;
        }

        // filesize validation
        if (!$this->isValidSize()) {
            $arg = File::format_size($this->getAllowedMaxFileSize($this->getFileExtension()));
            $this->errors[] = _t(
                'SilverStripe\\Assets\\File.TOOLARGE',
                'Filesize is too large, maximum {size} allowed',
                'Argument 1: Filesize (e.g. 1MB)',
                array('size' => $arg)
            );
            return false;
        }

        // extension validation
        if (!$this->isValidExtension()) {
            $this->errors[] = _t(
                'SilverStripe\\Assets\\File.INVALIDEXTENSION_SHORT_EXT',
                'Extension \'{extension}\' is not allowed',
                [ 'extension' => $this->getFileExtension() ]
            );
            return false;
        }

        return true;
    }
141544
public function check()
    {

        $config = $this->getConfig();

        if (isset($config['ext'])) {
            $this->setExt($config['ext']);
        }

        if (isset($config['folder'])) {

            $folder = $config['folder'];
            $this->setFolder($folder);


            if(!$this->getFileSystem()->exists($folder))
            {
                $this->getFileSystem()->createDir($folder);
                chmod($folder, 0777);
            }
        }else{

            return false;
        }

        // we have do something else

        if (function_exists('gzcompress') && function_exists('gzuncompress')) {
            return true;
        }
    }
733516
protected function uploadedDirIsWriteable()
    {
        $result = $this->Checkup->Webroot->isWriteable();

        return $result && array_key_exists(UPLOADED, $result) ? $result[UPLOADED] : false;
    }