Set files for send in request

@param string|array $file
@param string $name
@return \Slice\Http\Client
558924
public function setFiles($file, $name = null)
	{
		// Verifying if is array
		if (is_array($file)) {
			foreach ($file as $k => $v) {
				$this->setFiles($v,$k);
			}
		} else {
			$parray = &$this->files;
			
			if (file_exists($file)) {
				if (is_null($file)) {
					if (isset($parray[$name])) unset($parray[$name]);
				} else {
					if (is_null($name) || is_integer($name)) {
						$count = count($parray);
						$name = 'file_contents_' . $count;
					}
						
					$parray[$name] = $file;
				}
			} else {
				throw new RuntimeException('Invalid file, file not exists.');
			}	
		}
		
		return $this;
	}
1313382
public HttpRequest form(String name, File... files) {
		if (1 == files.length) {
			final File file = files[0];
			return form(name, file, file.getName());
		}
		return form(name, new MultiFileResource(files));
	}
221369
public function addAttachment($file, $name = null, $fileInfo = []) {
		$fileInfo['file'] = $file;
		if (!empty($name)) {
			$fileInfo = [$name => $fileInfo];
		} else {
			$fileInfo = [$fileInfo];
		}
		return $this->addAttachments($fileInfo);
	}
577066
protected function _setCurrentFile($file)
    {
        $this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
        return $this;
    }
1200079
public function getFile($name)
    {
        if (!isset($this->files)) {
            $files = $this->getUploadedFiles();
            foreach ($files as $file) {
                $key = $file->getKey();
                if (isset($key)) {
                    $this->files[$key] = $file;
                } else {
                    $this->files[] = $file;
                }
            }
        }
        if (isset($this->files[$name])) {
            return $this->files[$name];
        } else {
            throw new \InvalidArgumentException("Upload file '$name' is empty");
        }
    }
1063630
public function file(string $file, string $name = null) : self
    {
        $this->filePath = $file;

        if ( ! file_exists($file) || ! is_readable($file)) {
            throw new FileException('Cannot read file: ' . $file);
        }

        $this->fileName = $name ?? basename($this->filePath);
        $this->fileSize = filesize($file);

        return $this;
    }
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));
        }
    }
1166272
public function setFile($file) {
        if (!file_exists($file) || !is_readable($file)) {
            throw new InvalidArgumentException("The file '{$file}' cannot be opened.");
        }
        $this->file = $file;
        return $this;
    }
373311
public function setFiles(array $files)
    {
        foreach ($files as $file) {
            if (is_file($file)) {
                $file = new SplFileInfo($file, $file, $file);
            }

            if (!($file instanceof SplFileInfo)) {
                throw new InvalidArgumentException("File $file not exists.");
            }

            $this->files[$file->getRealPath()] = $file;
        }

        return $this;
    }
1157222
public function setFile($file)
    {

        //Return false if file does not exists;
        if (!$this->isFile($file)) {
            return false;
        }
        //Get the file info
        $this->file = $file;
        $this->pathinfo[$file] = pathinfo($file);

        //Return an instance of the file object;
        return $this;
    }
212062
public function fileGetContents($file)
    {
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('get')
            ->setUrl($file)
            ->addHeaders(['user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'])
            ->setOptions([
                'timeout' => $this->readFileTimeout, // set timeout to 1 seconds for the case server is not responding
            ])
            ->send();

        if ($response->isOk) {
            return $response->content;
        }

        throw new \Exception("File get contents '{$file}' error: ".$response->content);
    }
1194637
private function makeMigrationClass($name, $file)
    {
        if (($pos = strpos($name, '_')) === false) {
            throw new MigrationException('Name of the migration file "' . $name . '.php" is invalid. Format "<timestamp>_<classname>.php" expected.');
        }
        $class = substr($name, $pos + 1);

        /** @noinspection PhpIncludeInspection */
        require_once $file;

        if (!class_exists($class, false)) {
            throw new MigrationException('Migration class "' . $class . '" is not defined in file "' . $name . '.php".');
        }

        $instance = new $class;

        if (!($instance instanceof Migration)) {
            throw new MigrationException('Migration "' . $name . '" is invalid. The Class have to implements the interface \Core\Services\Contracts\Migration.');
        }

        return $instance;
    }
390368
public function uploadAssetFile(Locator $locator, $name, $file)
    {
        Validate::isString($name, 'name');
        Validate::notNull($file, 'file');

        $urlFile = $locator->getBaseUri().'/'.$name;
        $url = $urlFile.$locator->getContentAccessComponent();

        if (is_resource($file)) {
            $this->_uploadAssetFileFromResource($url, $file);
        } else {
            $this->_uploadAssetFileFromString($url, $file);
        }
    }
290746
public function send_file($file) {
        // First we create the 'resumable upload request'.
        $this->googleoauth->setHeader("Content-Length: 0");
        $this->googleoauth->setHeader("X-Upload-Content-Length: ". $file->get_filesize());
        $this->googleoauth->setHeader("X-Upload-Content-Type: ". $file->get_mimetype());
        $this->googleoauth->setHeader("Slug: ". $file->get_filename());
        $this->googleoauth->post(self::UPLOAD_URL);

        if ($this->googleoauth->info['http_code'] !== 200) {
            throw new moodle_exception('Cantpostupload');
        }

        // Now we http PUT the file in the location returned.
        $location = $this->googleoauth->response['Location'];
        if (empty($location)) {
            throw new moodle_exception('Nouploadlocation');
        }

        // Reset the curl object for actually sending the file.
        $this->reset_curl_state();
        $this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
        $this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());

        // We can't get a filepointer, so have to copy the file..
        $tmproot = make_temp_directory('googledocsuploads');
        $tmpfilepath = $tmproot.'/'.$file->get_contenthash();
        $file->copy_content_to($tmpfilepath);

        // HTTP PUT the file.
        $this->googleoauth->put($location, array('file'=>$tmpfilepath));

        // Remove the temporary file we created..
        unlink($tmpfilepath);

        if ($this->googleoauth->info['http_code'] === 201) {
            // Clear headers for further requests.
            $this->reset_curl_state();
            return true;
        } else {
            return false;
        }
    }
931195
public function loadFiles( $name, $files = [] ) {

		$filesToLoad	= Yii::$app->request->post( $name );
		$count			= count( $filesToLoad );

		if ( $count > 0 ) {

			$filesToLoad  = [];

			// TODO: Use existing file models using $files param.
			for( $i = 0; $i < $count; $i++ ) {

				$filesToLoad[] = new File();
			}

			File::loadMultiple( $filesToLoad, Yii::$app->request->post(), $name );

			return $filesToLoad;
		}

		return $files;
	}
560033
public function _($name = null)
    {
        if (isset($name)) {
            $this->path[] = $name;
        }
        $client = new static($this->host, $this->headers);
        $client->setPath($this->path);
        $client->setCurlOptions($this->curlOptions);
        $client->setRetryOnLimit($this->retryOnLimit);
        $this->path = [];

        return $client;
    }
630659
public function setFile($file) {
        $f = $file;
        if (preg_match('#^compress\.(.*)://(.*)#', $file, $r)) {
            $f = $r[2];
        }
        if(is_readable($f)) {
            $open = fopen($file, "rb");
            $this->file = $open;
        } else {
            $this->handleError("{$file} is not readable.");
        }

	}