Uploads a file.

@since 1.0.0

@param string $name     The name.
@param string $filename The filename.

@throws InvalidUploadedFileException If the filename is a non-existing file.
15060
public function uploadFile(string $name, string $filename): void
    {
        $sourceFile = FilePath::parse($filename);
        if (!file_exists($sourceFile->__toString())) {
            throw new InvalidUploadedFileException('File "' . $sourceFile . '" does not exist.');
        }

        $destinationFile = tempnam(sys_get_temp_dir(), 'php');
        copy($sourceFile->__toString(), $destinationFile);

        $this->setUploadedFile(
            $name,
            new UploadedFile(
                FilePath::parse($destinationFile),
                $sourceFile->__toString(),
                filesize($destinationFile)
            )
        );
    }
1075221
public function upload($filename, $destination)
    {
        if (isset($this[$filename])) {
            $file = $this[$filename];
            if (is_uploaded_file($file[static::TMP_NAME])) {
                try {
                    return move_uploaded_file($file[static::TMP_NAME], $destination);
                } catch (\Exception $e) {
                    var_dump($e->getMessage());
                    exit();
                }
            }
        }
        return false;
    }
484901
protected function loadFile($filename)
    {
        if (isset($this->aliases[$filename])) {
            $filename = $this->aliases[$filename];
        }

        switch (pathinfo($filename, PATHINFO_EXTENSION)) {
            case 'js':
            case 'json':
                $level = error_reporting(0);
                $json = file_get_contents($filename);
                error_reporting($level);

                if ($json === false) {
                    $err = error_get_last();
                    throw new InvalidArgumentException("Unable to open {$filename}: " . $err['message']);
                }

                $config = json_decode($json, true);
                // Throw an exception if there was an error loading the file
                if ($error = json_last_error()) {
                    $message = isset(self::$jsonErrors[$error]) ? self::$jsonErrors[$error] : 'Unknown error';
                    throw new RuntimeException("Error loading JSON data from {$filename}: ({$error}) - {$message}");
                }
                break;
            case 'php':
                if (!is_readable($filename)) {
                    throw new InvalidArgumentException("Unable to open {$filename} for reading");
                }
                $config = require $filename;
                if (!is_array($config)) {
                    throw new InvalidArgumentException('PHP files must return an array of configuration data');
                }
                break;
            default:
                throw new InvalidArgumentException('Unknown file extension: ' . $filename);
        }

        // Keep track of this file being loaded to prevent infinite recursion
        $this->loadedFiles[$filename] = true;

        // Merge include files into the configuration array
        $this->mergeIncludes($config, dirname($filename));

        return $config;
    }
1334918
public function setFile($name, $file, $filename = null)
    {
        $path = $this->fileLocator->locate($file);
        $this->resources[] = $resource = fopen($path, 'r');
        $this->getMultipartStreamBuilder()->addResource($name, $resource, ['filename' => $filename]);
    }
578501
protected function setHeader(string $name, $value)
    {
        if (!$this->isHeaderNameValid($name)) {
            throw new InvalidHeaderException('Header name is invalid.');
        }

        $normalized = strtolower($name);
        $value = $this->filterHeader($value);

        // Header may have been previously set with a different case. If so, remove that header.
        if (isset($this->headerNameMap[$normalized]) && $this->headerNameMap[$normalized] !== $name) {
            unset($this->headers[$this->headerNameMap[$normalized]]);
        }

        $this->headerNameMap[$normalized] = $name;
        $this->headers[$name] = $value;
    }
1031605
public function setDownload($filename = false) {
        $h = "attachment;";
        if ($filename) {
            $h .= "filename='" . $filename . "'";
        }
        $this['response']->setHeader("Content-Disposition", $h);
    }
1372470
static public function createFromFile($filename) {
		if (!file_exists($filename))
			throw new Exception('Invalid (filename) parameter! File does not exist!');

		$image_info = getimagesize($filename);
		if ($image_info === false)
			throw new Exception('Invalid (filename) parameter! File is corrupted!');

		switch ($image_info[2]) {
			case IMAGETYPE_JPEG:
			case IMAGETYPE_JPEG2000:
				$image = imagecreatefromjpeg($filename);
				break;
			case IMAGETYPE_PNG:
				$image = imagecreatefrompng($filename);
				break;
			case IMAGETYPE_GIF:
				$image = imagecreatefromgif($filename);
				break;
			case IMAGETYPE_WBMP:
				$image = imagecreatefromwbmp($filename);
				break;
			case IMAGETYPE_BMP:
				$image = imagecreatefrombmp($filename);
				break;
			default:
				throw new Exception('Unknown image format!');
				break;
		}

		return new self($image);
	}
1071944
protected function assertFilenameValid($filename)
    {
        $result = new ValidationResult();
        $this->validate($result, $filename);
        if (!$result->isValid()) {
            throw new ValidationException($result);
        }
    }
1196427
public function createChildFile($name)
    {
        if (
            strpos($name, '\\') !== false
            || strpos($name, '/') !== false
            || strpos($name, '..') !== false
        ) {
            throw new InvalidArgumentException("Wrong file name {$name}");
        }

        $class = $this->fileClass;

        return new $class($this->absolutePath . '/' . $name);
    }
729590
public function upload(string $filename, $source): UploadCommand
    {
        /** @var UploadCommand $command */
        $command = $this->builder->build(UploadCommand::class);
        $command->withFilename($filename)->withSource($source);

        return $command;
    }
843705
public function setFileName($fileName)
    {
        $this->fileName = $fileName;
        $this->setContentType(mime_content_type($this->fileName));
    }
625904
public function uploadFile(string $file, string $path, string $name)
    {
        // to store the file we have to make sure the directory exists
        foreach ($this->extractDirectories($path) as $dir) {
            // if change to directory fails
            // create the dir and change into it afterwards
            try {
                $this->chDir($dir);
            } catch (\Exception $e) {
                $this->mkDir($dir);
                $this->chDir($dir);
            }
        }
        if (!$this->put($name, $file, FTP_BINARY)) {
            $error   = error_get_last();
            $message = $error['message'];
            throw new RuntimeException(sprintf('error uploading file: %s - %s', $file, $message));
        }
    }
1063648
public function allowedUpload($originalFilename)
    {
        // Check if file_uploads ini directive is true
        if (Ini::getBool('file_uploads') === false) {
            throw new IOException('File uploads are not allowed, check the file_uploads ini directive.');
        }
        // no UNIX-hidden files
        if ($originalFilename[0] === '.') {
            return false;
        }
        // only whitelisted extensions
        $extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
        $allowedExtensions = $this->getAllowedUploadExtensions();

        return in_array($extension, $allowedExtensions);
    }
195156
private void delete(String name) {
        File f = new File(name);
        if (f.exists()) {
            f.delete();
        }
    }
961564
protected function validateHeaderName($headerName) : void
	{
		if (! \is_string($headerName))
		{
			throw new \InvalidArgumentException('Header name must be a string');
		}
		else if (! \preg_match(HeaderInterface::RFC7230_TOKEN, $headerName))
		{
			throw new \InvalidArgumentException(\sprintf('The given header name "%s" is not valid', $headerName));
		}
	}
200189
private void uploadFile(String fileName) throws IOException, NoSuchAlgorithmException, InvalidKeyException,
      XmlPullParserException, InvalidEndpointException, InvalidPortException,
      InvalidBucketNameException, InsufficientDataException, NoResponseException,
      ErrorResponseException, InternalException, InvalidArgumentException {

    /* play.min.io for test and development. */
    MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
                                              "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
    /* Amazon S3: */
    // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com",
    // "YOUR-ACCESSKEYID",
    // "YOUR-SECRETACCESSKEY");

    File file = new File(fileName);
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
      ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(
          this,
          "Uploading... " + file.getAbsolutePath(),
          bis);

      pmis.getProgressMonitor().setMillisToPopup(10);
      minioClient.putObject("bank", "my-objectname", pmis, bis.available(), "application/octet-stream");
      System.out.println("my-objectname is uploaded successfully");
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
962587
public function save(File $file, $filename = null)
    {
        if ($filename !== null) {
            $file->setFilename($filename);
        }

        $this->filesystem->write($file);
    }