Assert that the temp file exists and is an uploaded file

@throws \RuntimeException if the file doesn't exist or is not an uploaded file.
508648
protected function assertTmpFile()
    {
        if (empty($this->tmpName)) {
            throw new \RuntimeException("There is no tmp_file for " . $this->getDesc()
                . ": " . $this->getErrorDescription());
        }
        
        if (!file_exists($this->tmpName)) {
            throw new \RuntimeException("The " . $this->getDesc() . " no longer exists or is already moved");
        }
        
        if ($this->assertIsUploadedFile && !$this->isUploadedFile($this->tmpName)) {
            throw new \RuntimeException("The specified tmp_name for " . $this->getDesc() . " doesn't appear"
                . " to be uploaded via HTTP POST");
        }
    }
678610
protected function isSaved(): bool
    {
        return $this->filesystem->has($this->path)
            && $this->filesystem->getTimestamp($this->path) > $this->file->getUpdatedAt();
    }
1044066
public function fileExists()
    {
        $this->filenameIsValide($this->name);

        return file_exists($this->getPath()) || is_dir($this->base_dir."/".$this->name);
    }
127243
public function hasFile($name)
    {
        //See if it makes sense to use dot notation
        if (isset($_FILES[$name])) {
            $file = $_FILES[$name];
            return isset($file['tmp_name']) && file_exists($file['tmp_name']) && is_uploaded_file($file['tmp_name']);
        }
        return false;
//        return $this->files->has($name);
    }
1005141
private function checkDir() : void
    {
        $dir = dirname($this->path);
        if (!is_dir($dir)) {
            if (file_exists($dir)) {
                throw new \RuntimeException($dir . ' exists and is not a directory.');
            }
            if (!@mkdir($dir, 0755, true)) {
                throw new \RuntimeException($dir . ' does not exist and could not be created.');
            }
        }
    }
742581
public static function checkTemporaryFolder() {
		
		if (!file_exists(static::TEMP_FOLDER) or !is_dir(static::TEMP_FOLDER)) {
			
			// remove any file named as wanted temporary folder
			@unlink(static::TEMP_FOLDER);

			// create the folder
			$old = umask(0);
			if (!mkdir(static::TEMP_FOLDER, 0777, TRUE)) {
				trigger_error('Directory creation on ' . static::TEMP_FOLDER . ' failed');
				$ret = FALSE;
			}
			umask($old);
			
			// sets full permissions
			if (!chmod(static::TEMP_FOLDER, 0777)) {
				trigger_error('Set permissions on directory ' . static::TEMP_FOLDER . ' failed');
				$ret = FALSE;
			}
			
		}
		
	}
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;
    }
264847
public function run(): void
    {
        if (!$this->config->isLoadedFromFile()) {
            throw new \RuntimeException('No configuration to edit');
        }

        $this->checkHook();
        $this->checkChange();

        $change = $this->createChange();
        $change->applyTo($this->config);
        Config\Util::writeToDisk($this->config);

        $this->io->write('Configuration successfully updated');
    }
1033962
private void checkFile() throws IORuntimeException {
		if (false == file.exists()) {
			throw new IORuntimeException("File not exist: " + file);
		}
		if (false == file.isFile()) {
			throw new IORuntimeException("Not a file:" + file);
		}
	}
306227
private function verifyAndSave()
    {
        $this->pharValidator->assertPharValid($this->tmpPharPath);

        if (!@rename($this->tmpPharPath, $this->target)) {
            throw new RuntimeException(
                sprintf(
                    'Could not write to file "%s": %s',
                    $this->target,
                    @error_get_last()['message']
                )
            );
        }
        if (!@rename($this->tmpPubkeyPath, $this->target . '.pubkey')) {
            throw new RuntimeException(
                sprintf(
                    'Could not write to file "%s": %s',
                    $this->target,
                    @error_get_last()['message']
                )
            );
        }

        chmod($this->target, 0755);
    }
1314640
public function save()
    {
        if ($path = $this->getProjectPath()) {
            $path .= '/' . $this->getOutputFile();
            file_put_contents($path, serialize($this->getContainer()));
        } else {
            throw new \RuntimeException('No project path provided.');
        }
        return $this;
    }
677450
private function validate()
    {
        if (!class_exists($this->class)) {
            throw new \RuntimeException(sprintf('Class %s does not exist, is this the correct namespace?', $this->class));
        }
        if (!in_array($this->method, get_class_methods($this->class))) {
            throw new \RuntimeException(sprintf('The method "%s" does not exist in "%s" class.', $this->method, $this->class));
        }
    }
998104
private function mustLoadStoredRoutine(): bool
  {
    // If this is the first time we see the source file it must be loaded.
    if (!isset($this->phpStratumOldMetadata)) return true;

    // If the source file has changed the source file must be loaded.
    if ($this->phpStratumOldMetadata['timestamp']!=$this->filemtime) return true;

    // If the value of a placeholder has changed the source file must be loaded.
    foreach ($this->phpStratumOldMetadata['replace'] as $place_holder => $old_value)
    {
      if (!isset($this->replacePairs[strtoupper($place_holder)]) ||
        $this->replacePairs[strtoupper($place_holder)]!==$old_value)
      {
        return true;
      }
    }

    // If stored routine not exists in database the source file must be loaded.
    if (!isset($this->rdbmsOldRoutineMetadata)) return true;

    // If current sql-mode is different the source file must reload.
    if ($this->rdbmsOldRoutineMetadata['sql_mode']!=$this->sqlMode) return true;

    // If current character set is different the source file must reload.
    if ($this->rdbmsOldRoutineMetadata['character_set_client']!=$this->characterSet) return true;

    // If current collation is different the source file must reload.
    if ($this->rdbmsOldRoutineMetadata['collation_connection']!=$this->collate) return true;

    return false;
  }
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;
	}
395615
protected function persist()
    {
        if (false === file_put_contents($this->filename, $this->serialize())) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException('Unable to open file ' . $this->filename);
            // @codeCoverageIgnoreEnd
        }
    }
717396
public function hasFile()
    {
        foreach ($this->fields() as $field) {
            if ($field instanceof Field\File) {
                return true;
            }
        }

        return false;
    }
1160139
public function load()
    {
        $raw = parent::load();

        try {
            return $raw !== false ? $this->formatter->decode($raw) : false;
        } catch (RuntimeException $e) {
            throw new RuntimeException(sprintf("Failed to load file '%s': %s", $this->getFilePath(), $e->getMessage()), $e->getCode(), $e);
        }
    }