Upload material.
@param string $type
@param string $path
@param array $form
@return mixed
@throws \yii\httpclient\Exception
434479
protected function uploadMedia($type, $path, array $form = [])
    {
        if (!file_exists($path) || !is_readable($path)) {
            throw new InvalidArgumentException("File does not exist, or the file is unreadable: '$path'");
        }
        $form['type'] = $type;
        return $this->upload($this->getAPIByType($type), ['media' => $path], $form);
    }
830888
public static function process($uploadedFile, $path)
    {
        if (!$uploadedFile || $uploadedFile->hasError) {
            throw new Exception('Failed to upload file');
        }
        $chunk = (int)Yii::$app->request->getBodyParam('chunk', 0);
        $totalChunks = (int)Yii::$app->request->getBodyParam('chunks', 0);
        $out = fopen("$path.part", $chunk == 0 ? 'wb' : 'ab');
        if (!$out) {
            throw new Exception('Failed to open output stream');
        }
        // Read binary input stream and append it to temporary .part file
        $in = fopen($uploadedFile->tempName, 'rb');
        if ($in) {
            while ($buff = fread($in, 4096)) {
                fwrite($out, $buff);
            }
        } else {
            throw new Exception('Failed to open input stream');
        }
        fclose($in);
        fclose($out);
        unlink($uploadedFile->tempName);
        // Check if all chunks have been processed
        if (!$totalChunks || $chunk == $totalChunks - 1) {
            // Strip the temp .part suffix off
            rename("$path.part", $path);
            return true;
        }
        return false;
    }
188355
public static function upload($field, $title, $action, $value = '', $type = Upload::TYPE_FILE)
    {
        $upload = new Upload($field, $title, $value);
        $upload->uploadType($type)->action($action);
        return $upload;
    }
1336626
public function add(array $post, Form $form = null)
    {
        $model  = $this->getModel();
        $form   = ($form instanceof Form) ?
            $form->setData($post) :
            $this->prepareForm($model, $post, true, true);
        $argv   = compact('post', 'form');
        $argv   = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_PRE_ADD, $this, $argv);

        if (!$form->isValid()) {
            return $form;
        }

        $saved  = $this->save($form->getData());
        $argv   = compact('post', 'form', 'saved');
        $argv   = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_POST_ADD, $this, $argv);

        return $saved;
    }
1154793
protected function execute($request_type, $form = array())
    {
        // Set the HTTP request type
        curl_setopt($this->client->ch, CURLOPT_CUSTOMREQUEST, $request_type);

        // If additional data is delivered, we will send it along with the API request
        if (is_array($form) && ! empty($form)) {
            curl_setopt($this->client->ch, CURLOPT_POSTFIELDS, $this->httpBuildQuery($form, '', '&'));
        }

        // Store received headers in temporary memory file, remember sent headers
        $fh_header = fopen('php://temp', 'w+');
        curl_setopt($this->client->ch, CURLOPT_WRITEHEADER, $fh_header);
        curl_setopt($this->client->ch, CURLINFO_HEADER_OUT, true);

        // Execute the request
        $response_data = curl_exec($this->client->ch);

        if (curl_errno($this->client->ch) !== 0) {
            // An error occurred
            fclose($fh_header);
            throw new Exception(curl_error($this->client->ch), curl_errno($this->client->ch));
        }

        // Grab the headers
        $sent_headers = curl_getinfo($this->client->ch, CURLINFO_HEADER_OUT);
        rewind($fh_header);
        $received_headers = stream_get_contents($fh_header);
        fclose($fh_header);

        // Retrieve the HTTP response code
        $response_code = (int) curl_getinfo($this->client->ch, CURLINFO_HTTP_CODE);

        // Return the response object.
        return new Response($response_code, $sent_headers, $received_headers, $response_data);
    }
759183
public static function create($option = [], $type = self::TYPE_LOCAL)
    {
        $class_name = '\\cms\\upload\\driver\\' . ucfirst($type) . 'Upload';
        if (class_exists($class_name)) {
            try {
                return $class_name::instance($option);
            } catch (\Exception $e) {}
        }
    }
698458
protected function upload(string $path, $contents, string $mode)
    {
        $path = $this->applyPathPrefix($path);

        try {
            $object = $this->client->upload($path, $contents, $mode);
        } catch (BadRequest $e) {
            return false;
        }

        return $this->normalizeResponse($object);
    }
892502
public function installExtensionFromFolder($path, $type = 'Extension')
	{
		$this->amOnPage('/administrator/index.php?option=com_installer');
		$this->waitForText('Extensions: Install', '30', array('css' => 'H1'));
		$this->click(array('link' => 'Install from Folder'));
		$this->debug('I enter the Path');
		$this->fillField(array('id' => 'install_directory'), $path);
		$this->click(array('id' => 'installbutton_directory'));
		$this->waitForText('was successful', TIMEOUT, array('id' => 'system-message-container'));
		$this->debug("$type successfully installed from $path");
	}
453176
public static function file($path, $type = null)
    {
        $response = new self(
            Status::OK,
            new PhpStream($path, 'rb')
        );
        if (isset($type)) {
            $response->setHeader('Content-Type', $type);
        }
        return $response;
    }
716902
private function handleUpload(FormInterface $form, DirectoryInterface $directory)
    {
        /** @var UploadedFile[] $files */
        $files = $form->get('select')->getData();
        $permissions = $this->app['filepermissions'];

        foreach ($files as $fileToProcess) {
            $fileToProcess = [
                'name'     => $fileToProcess->getClientOriginalName(),
                'tmp_name' => $fileToProcess->getPathname(),
            ];

            $originalFilename = $fileToProcess['name'];
            $filename = basename($originalFilename);
            $filename = $this->app['upload.sanitizer']->slugify($filename, $this->app['config']->get('general/upload/replacement', '-'));

            try {
                $isAllowed = $permissions->allowedUpload($filename);
            } catch (IOException $e) {
                $this->flashes()->error($e->getMessage());

                continue;
            }

            if ($isAllowed) {
                $this->processUpload($directory, $filename, $fileToProcess);
            } else {
                $extensionList = [];
                foreach ($permissions->getAllowedUploadExtensions() as $extension) {
                    $extensionList[] = '<code>.' . htmlspecialchars($extension, ENT_QUOTES) . '</code>';
                }
                $extensionList = implode(' ', $extensionList);
                $this->flashes()->error(
                    Trans::__("File '%file%' could not be uploaded (wrong/disallowed file type). Make sure the file extension is one of the following:", ['%file%' => $filename])
                    . $extensionList
                );
            }
        }
    }
76448
private function uploadMediaChunked($path, $parameters)
    {
        // Init
        $init = $this->http('POST', self::UPLOAD_HOST, $path, [
            'command' => 'INIT',
            'media_type' => $parameters['media_type'],
            'total_bytes' => filesize($parameters['media'])
        ]);
        // Append
        $segment_index = 0;
        $media = fopen($parameters['media'], 'rb');
        while (!feof($media))
        {
            $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
                'command' => 'APPEND',
                'media_id' => $init->media_id_string,
                'segment_index' => $segment_index++,
                'media_data' => base64_encode(fread($media, self::UPLOAD_CHUNK))
            ]);
        }
        fclose($media);
        // Finalize
        $finalize = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
            'command' => 'FINALIZE',
            'media_id' => $init->media_id_string
        ]);
        return $finalize;
    }
83346
function post($path, $body, $contentType = null)
    {
        return $this->dispatchRequest(
            $this->buildRequest('POST', $path, $body, $contentType)
        );
    }
899569
public static function delete(string $path, string $type):int
    {
        try {
            switch ($type) {
                case "directory":
                    if (is_link($path)) {
                        unlink($path);
                    } elseif (is_dir($path)) {
                        try {
                            self::recursiveRmdir($path);
                        } catch (\Exception $e) {
                            throw new \Exception("Server Manager delete error =>" . $e->getMessage());
                        }
                    }
                    break;
                case "file":
                    if (is_link($path)) {
                        unlink($path);
                    } elseif (file($path)) {
                        try {
                            unlink($path);
                        } catch (\Exception $e) {
                            throw new \Exception("Server Manager delete error =>" . $e->getMessage());
                        }
                    }
                    break;
            }
        } catch (\Exception $exception) {
            throw new \Exception("Server Error : Cannot delete $type element => ".$exception);
        }

        return (1);
    }
90544
public static function addToQueue($path, $type)
    {
        if ($type != self::TYPE_DIR && $type != self::TYPE_FILE) {
            throw new \Exception(sprintf('Invalid $type parameter "%s"', $type));
        }

        self::$cleanupQueue[] = ['path' => $path, 'type' => $type];
    }
82456
public function open($path, $type = null, $password = null)
    {
        if (null === $type) {
            $type = $this->guessAdapterExtension($path);
        }

        try {
            $adapter = $this->getAdapterFor($this->sanitizeExtension($type));
            if (method_exists($adapter, 'setPassword') && $password){
                $adapter->setPassword($password);
            }
            return $adapter->open($path);
        } catch (ExceptionInterface $e) {
            throw new RuntimeException('Unable to open archive', $e->getCode(), $e);
        }
    }
971531
public function file($field, $path, $type, $name)
    {
        $name = basename($name);
        if (class_exists('CURLFile')) {
            $this->set('CURLOPT_SAFE_UPLOAD', true);
            $file = curl_file_create($path, $type, $name);
        } else {
            $file = "@{$path};type={$type};filename={$name}";
        }
        return $this->post($field, $file);
    }
1230416
function post($path, $body, $contentType = null)
	{
		return $this->_dispatchRequest(
			$this->_buildRequest('POST', $path, $body, $contentType)
		);
	}