Download

@param string $file
514381
public static function start(String $file)
    {
        if( ! Info::available($file) )
        {
            throw new Exception\FileNotFoundException($file);
        }

        self::readFileContent($file);
    }
581422
public function download($file, $filename = '', $options = array())
    {
        $readfile = empty($options['text']);

        if ($readfile && !is_file($file)) {
            return null;
        }

        if ($readfile && empty($filename)) {
            $filename = basename($file);
        }

        $size = $readfile ? filesize($file) : strlen($file);

        $this->addHeader('Expires', 0)
            ->addHeader('Pragma', 'public')
            ->addHeader('Content-Length', $size)
            ->addHeader('Cache-Control', 'must-revalidate')
            ->addHeader('Content-Description', 'File Transfer')
            ->addHeader('Content-Type', 'application/octet-stream')
            ->addHeader('Content-Disposition', 'attachment; filename=' . $filename)
            ->addOptionalHeaders($options)
            ->sendHeaders();

        if ($readfile) {
            readfile($file);
        } else {
            echo $file;
        }

        exit;
    }
1134992
public function download($files, $options = [])
    {
        if (is_string($files)) {
            if (is_string($options) && strpos($options, '://') === false) {
                $return_file = $options;
            } else {
                $path = parse_url($files, PHP_URL_PATH);
                if ($pos = strrpos($path, '.')) {
                    $ext = strtolower(substr($path, $pos));
                    if ($ext === '.php' || preg_match('#^\.\w+$#', $ext) === 0) {
                        $ext = '.tmp';
                    }
                } else {
                    $ext = '.tmp';
                }
                $return_file = $this->alias->resolve('@tmp/download/' . md5($files . gethostname()) . $ext);
            }
            $files = [$files => $return_file];
        } else {
            if (is_int($options)) {
                $options = ['concurrent' => $options];
            } elseif (is_float($options)) {
                $options = ['timeout' => $options];
            } elseif (is_string($options)) {
                $options = [preg_match('#^https?://#', $options) ? CURLOPT_REFERER : CURLOPT_USERAGENT => $options];
            }
            $return_file = null;
        }

        $mh = curl_multi_init();

        $template = curl_init();

        if (isset($options['timeout'])) {
            $timeout = $options['timeout'];
            unset($options['timeout']);
        } else {
            $timeout = 10;
        }

        if (isset($options['concurrent'])) {
            $concurrent = $options['concurrent'];
            unset($options['concurrent']);
        } else {
            $concurrent = 10;
        }

        curl_setopt($template, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($template, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($template, CURLOPT_USERAGENT, self::USER_AGENT_IE);
        curl_setopt($template, CURLOPT_HEADER, 0);
        /** @noinspection CurlSslServerSpoofingInspection */
        curl_setopt($template, CURLOPT_SSL_VERIFYHOST, false);
        /** @noinspection CurlSslServerSpoofingInspection */
        curl_setopt($template, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($template, CURLOPT_BINARYTRANSFER, true);

        foreach ($options as $k => $v) {
            if (is_int($k)) {
                curl_setopt($template, $k, $v);
            }
        }

        foreach ($files as $url => $file) {
            $file = $this->alias->resolve($file);
            if (is_file($file)) {
                unset($files[$url]);
            } else {
                $this->filesystem->dirCreate(dirname($file));
                $files[$url] = $file;
            }
        }

        $handles = [];
        $failed = [];
        do {
            foreach ($files as $url => $file) {
                if (count($handles) === $concurrent) {
                    break;
                }
                $curl = curl_copy_handle($template);
                $id = (int)$curl;

                curl_setopt($curl, CURLOPT_URL, $url);
                $fp = fopen($file . '.tmp', 'wb');
                curl_setopt($curl, CURLOPT_FILE, $fp);

                curl_multi_add_handle($mh, $curl);
                $handles[$id] = ['url' => $url, 'file' => $file, 'fp' => $fp];

                unset($files[$url]);
            }

            $running = null;
            while (curl_multi_exec($mh, $running) === CURLM_CALL_MULTI_PERFORM) {
                null;
            }

            usleep(100);

            while ($info = curl_multi_info_read($mh)) {
                $curl = $info['handle'];
                $id = (int)$curl;

                $url = $handles[$id]['url'];
                $file = $handles[$id]['file'];

                fclose($handles[$id]['fp']);

                if ($info['result'] === CURLE_OK) {
                    rename($file . '.tmp', $file);
                } else {
                    $failed[$url] = curl_strerror($curl);
                    unlink($file . '.tmp');
                }

                curl_multi_remove_handle($mh, $curl);
                curl_close($curl);

                unset($handles[$id]);
            }
        } while ($handles);

        curl_multi_close($mh);
        curl_close($template);

        if ($return_file) {
            return $failed ? false : $return_file;
        } else {
            return $failed;
        }
    }
1090565
public static function loadFile($file)
    {
        $json = new Json();

        return self::create($json->decodeFile($file), $json);
    }
79863
public function downloadUrl($file)
    {
        if (!$file) {
            return '';
        }

        $parts = explode(';', $file);
        $fileId = $parts[0];

        $src = $this->router->generate('frontendmedia_download', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_URL);

        return $src;
    }
354489
protected function queueUploadedFile($file)
    {
        // Get the real path of the file
        $file = $this->getFileManager()
            ->make($file)
            ->getRealPath();

        // Create the unique directory name and file to save into
        $file_target = $this->joinPaths(
            str_replace('.', '-', uniqid(rand(), true)),
            basename($file)
        );

        // Parse the queue path
        $queue_path = $this->getInterpolator()->interpolate(
            $this->config('queue_path')
        );

        // Determine if the path is locale and just simple move it,
        // otherwise use the disk driver to move the attachment.
        if ($local_path = realpath($queue_path)) {
            $target = $this->joinPaths($local_path, $file_target);

            // Ensure the target directory exists
            if (is_dir(dirname($target)) === false) {
                mkdir(dirname($target), 0777, true);
            }

            // Move the file
            rename($file, $target);
        }
        else {
            $this->move(
                $file, $this->joinPaths($queue_path, $file_target)
            );
        }

        // Save the information for later
        $this->instanceWrite('queue_state', self::QUEUE_WAITING);
        $this->instanceWrite('queued_file', $file_target);
    }
356415
public function load(string $file)
    {
        $file = $this->sanitizeFileName($file);
        if (empty($this->loaded)
            && !empty($this->beforeFirstTimeLoadCallBack)
            && $this->isValid()
        ) {
            $callback = $this->beforeFirstTimeLoadCallBack;
            $callback($this);
            $this->beforeFirstTimeLoadCallBack = false;
        }

        $this->loaded[$file] = isset($this->loaded[$file])
            ? $this->loaded[$file]+1
            : 1;
        return RequireBinding::with(($this->getThemePath() . $file), $this);
    }
799298
public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);

        if (! is_null($name)) {
            return $response->setContentDisposition($disposition, $name, $this->fallbackName($name));
        }

        return $response;
    }
1110034
public function load(string $file)
    {
        $this->data = Yaml::parse(file_get_contents($file));
        $this->filename = basename($file);
    }
776877
public function file($file)
    {
        $filePaths = loader()->getPublicDirs(true);

        foreach ($filePaths as $filePath) {
            if (is_file($filePath . $file)) {
                return path_to_url($filePath . $file);
                break;
            }
        }
    }
1353985
public function download($file, $filename = '', $options = array())
    {
        $this->response->download($file, $filename, $options);
    }
1115574
protected function tryLoad($file)
    {
        try {
            return XmlUtils::loadFile($file, __DIR__ . static::SCHEMA_LOCATION);
        } catch (\InvalidArgumentException $e) {
            throw new InvalidWebspaceException(
                sprintf(
                    'Could not parse webspace XML file "%s"',
                    $file
                ),
                null,
                $e
            );
        }
    }
895781
public function loadFile($file)
    {
        $xml = file_get_contents($file);
        if (!$xml) {
            return false;
        }

        try {
            $this->setXml($xml);
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
501152
public function fileGet($file)
    {
        if (($r = @file_get_contents($this->alias->resolve($file))) === false) {
            throw new FileNotFoundException($file);
        }

        return $r;
    }
1119081
protected function fileLoading($file)
    {
        if (class_exists($file, true))
        {
            $listener = new $file();
            $object   = new \ReflectionClass($file);

            if ($object->implementsInterface('Distilleries\Expendable\Contracts\ListenerContract'))
            {
                $listener->listen();
                $this->loaded[$file] = $listener;
            }

        }
    }
714017
@GET
  @Path("/download/{file}")
  public Response downloadFile(final @PathParam("file") String file) {
    Config config = createConfig();
    String uploadDir = config.getStringValue(FILE_SYSTEM_DIRECTORY);
    String filePath = uploadDir + "/" + file;
    return getResponseByFile(filePath);
  }
332490
public function read($file)
    {
        $this->filePath = $file;
        $this->config = parse_ini_file($this->filePath);
    }