Validates the uploaded image. Returns the temporary name of the uploaded file.
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;
   }
289593
private function upload_image()
    {

        /* validate the image */
        $validation    = Validator::make($this->image, array($this->input => $this->rules));
        $errors        = array();
        $original_name = $this->image[$this->input]->getClientOriginalName();
        $path          = '';
        $filename      = '';
        $resizes       = '';

        if ($validation->fails()) {
            /* use the messages object for the erros */
            $errors = implode('. ', $validation->messages()->all());
        } else {
            if ($this->random) {
                if (is_callable($this->random_cb)) {
                    $filename = call_user_func($this->random_cb, $original_name);
                } else {
                    $ext      = File::extension($original_name);
                    $filename = $this->generate_random_filename().'.'.$ext;
                }
            } else {
                $filename = $original_name;
            }

            /* upload the file */
            $save = $this->image[$this->input]->move($this->path, $filename);
            //$save = Input::upload($this->input, $this->path, $filename);

            if ($save) {
                $path = $this->path.$filename;

                if (is_array($this->image_sizes)) {
                    $resizer = new Resize();
                    $resizes = $resizer->create($save, $this->path, $filename, $this->image_sizes);
                }
            } else {
                $errors = 'Could not save image';
            }
        }

        return compact('errors', 'path', 'filename', 'original_name', 'resizes');
    }
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;
    }
397531
def check_file(self):
        
        try:
            image_type = ".{0}".format(self.image.split(".")[1])
            if image_type not in self.file_format:
                print("Format: '{0}' not recognized. Use one of "
                      "them:\n{1}".format(self.image.split(".")[1],
                                          ", ".join(self.file_format)))
                raise SystemExit()
        except IndexError:
            print("slpkg: Error: Image file suffix missing")
            raise SystemExit()
581232
public function isValidMime()
    {
        $extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));

        // we can't check filenames without an extension or no temp file path, let them pass validation.
        if (!$extension || !$this->tmpFile['tmp_name']) {
            return true;
        }

        $expectedMimes = $this->getExpectedMimeTypes($this->tmpFile);
        if (empty($expectedMimes)) {
            throw new MimeUploadValidatorException(
                sprintf('Could not find a MIME type for extension %s', $extension)
            );
        }

        $fileInfo = new finfo(FILEINFO_MIME_TYPE);
        $foundMime = $fileInfo->file($this->tmpFile['tmp_name']);
        if (!$foundMime) {
            throw new MimeUploadValidatorException(
                sprintf('Could not find a MIME type for file %s', $this->tmpFile['tmp_name'])
            );
        }

        foreach ($expectedMimes as $expected) {
            if ($this->compareMime($foundMime, $expected)) {
                return true;
            }
        }

        return false;
    }
1332757
def image_upload_to(self, filename):
        
        now = timezone.now()
        filename, extension = os.path.splitext(filename)

        return os.path.join(
            UPLOAD_TO,
            now.strftime('%Y'),
            now.strftime('%m'),
            now.strftime('%d'),
            '%s%s' % (slugify(filename), extension))
218192
private String validateFile(final MultipartFile file) {
        final String filename = StringUtils
                .cleanPath(file.getOriginalFilename());
        if (file.isEmpty()) {
            throw new StorageException(
                    "Failed to store empty file " + filename);
        }
        if (filename.contains("..")) {
            // This is a security check
            throw new StorageException(
                    "Cannot store file with relative path outside current"
                    + " directory "
                    + filename);
        }
        return filename;
    }
1166844
def temp_filename(self):
        
        # TODO: it would be nice to get this to behave more like a
        # context so we can make sure these temporary files are
        # removed, regardless of whether an error occurs or the
        # program is terminated.
        handle, filename = tempfile.mkstemp()
        os.close(handle)
        return filename
1189990
public function beforeValidate()
    {
        $this->fileName = $this->owner->getAttribute($this->fileField);
        if (!is_string($this->fileName)) {
            $this->fileName = @$this->owner->oldAttributes[$this->fileField];
        }
        if (
            (!$files = UploadedFile::getInstance($this->owner, $this->fileField))
            && (!$files = UploadedFile::getInstances($this->owner, $this->fileField))     
        ) {
            return true;
        }
        return $this->owner->setAttribute($this->fileField, $files);
    }
45461
public function isValid() {
		
		$file = $this -> getFile();

		$messages = [

			UPLOAD_ERR_FORM_SIZE 	=> 'File exceeds the maximum file size that was specified in the HTML form',
			UPLOAD_ERR_PARTIAL 		=> 'File was only partially uploaded',
			UPLOAD_ERR_NO_FILE		=> 'No file was uploaded',
			UPLOAD_ERR_NO_TMP_DIR	=> 'Missing a temporary folder',
			UPLOAD_ERR_CANT_WRITE	=> 'Failed to write file to disk',
			UPLOAD_ERR_EXTENSION	=> 'An extension stopped the file upload'
		];

		if(false === isset($messages[$file['error']])) {
			return true;
		}

		$this -> setMessage($messages[$file['error']]);

		return false;
	}
1221863
def validate (self):
    
    if not os.path.isfile(self.pathname):
      self.message.append('Filename "%s" does not exist.')
    else:
      try:
        with open(self.pathname, 'r') as stream:
          pass
      except IOError:
        self.messages.append('Could not open "%s" for reading.' % self.pathname)

    for line in self.commands:
      messages = [ ]
      if line.cmd and not line.cmd.validate(messages):
        msg = 'error: %s: %s' % (line.cmd.name, " ".join(messages))
        self.log.messages.append(msg)

    return len(self.log.messages) == 0
86928
public function upload()
    {
      if ($this->error !== '') {
        return false;
      }

      $isValid = $this->contraintsValidator();

      $isSuccess = $isValid && $this->isSaved($this->_files['tmp_name'], $this->getFullPath());

      return $isSuccess ? $this : false;
    }
509643
def _validate_image_rank(self, img_array):
        
        if img_array.ndim == 1 or img_array.ndim > 3:
            msg = "{0}D imagery is not allowed.".format(img_array.ndim)
            raise IOError(msg)
364317
public function validateFile()
    {
        $totalChunks = $this->request->getTotalChunks();
        $totalChunksSize = 0;

        for ($i = $totalChunks; $i >= 1; $i--) {
            $file = $this->getChunkPath($i);
            if (!file_exists($file)) {
                return false;
            }
            $totalChunksSize += filesize($file);
        }

        return $this->request->getTotalSize() == $totalChunksSize;
    }
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
        )
935036
def __isValidFilename(self, filename):
        """"""
        if filename and isinstance(filename, string_types):
            if re.match(r'^[\w\d\_\-\.]+$', filename, re.I):
                if self.__isValidTGZ(filename) or self.__isValidZIP(filename):
                    return True
        return False
1019835
def filename(self):
        
        if self._filename:
            return self._filename
        else:
            with tempfile.NamedTemporaryFile(delete=False) as f:
                f.write(self._bytes)
            return f.name