Force a file download by setting headers.
@param string path to file
@param string extension
@param string file name on client side
@example download('folder/error_log.pdf')
@example download('folder/error_log.pdf', 'pdf' ,'log.pdf')
@return boolean
553177
public static function download($path = false, $extension = false, $name = false) {

        if($path && File::isFile($path)) {

            if(!$extension) {
                $extension = File::extension($path);
            }

            if(!$name) {
                $name = basename($path);
            }

            header('Content-Type: application/' . $extension);
            header("Content-Transfer-Encoding: Binary");
            header("Content-disposition: attachment; filename=" . $name);
            readfile($path);
            exit();
        }

        return false;
    }
647611
public function download($name,$path){
        $ruta = $this->getFullPath().$path.$name;
        if( $this->config['debug'] ) $this->_log('$ruta - '.$ruta);
        if($this->validNameFile($name) && file_exists($ruta) && is_file($ruta) ){
            $response = new Response(file_get_contents($ruta));
            $response->headers->set('Content-Type', 'application/octet-stream');
            $d = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,$name);
            $response->headers->set('Content-Disposition', $d);
            $response->send();
        }else{
            exit();
            // return null;
        }
    }
996086
public function download(
        $file,
        string $name = null,
        array $headers = [],
        string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT
    ) : BinaryFileResponse {
        $response = new BinaryFileResponse($file, HttpResponse::HTTP_OK, $headers, true, $disposition);

        $response->prepare(HttpRequest::createFromGlobals());

        if ( ! is_null($name)) {
            $response = $response->setContentDisposition(
                $disposition,
                $name,
                iconv('UTF-8', 'ASCII//TRANSLIT', $name)
            );
        }

        return $this->createOnly ? $response : $response->send();
    }
436776
private function static_file_default(
		string $path, int $cache=0, string $disposition=null
	) {
		if (file_exists($path))
			static::send_file($path, $disposition, 200, $cache);
		$this->abort(404);
	}
636414
public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        respondWith(response()->download($file, $name, $headers, $disposition ));
    }
1065060
private function isFilenameEndingWithExtension($name)
	{
		return \strrpos($name, self::EXTENSION) === (\strlen($name) - self::EXTENSION_LENGTH);
	}
123422
public function write($path, $content, $extension = 'html', $filename = 'index')
    {
        $directory = sprintf('%s/%s', $this->destination, trim($path, '/'));
        $file      = sprintf('%s.%s', $filename, $extension);

        if (!$this->files->exists($directory)) {
            $this->files->mkdir($directory);
        }

        $this->files->dumpFile(sprintf('%s/%s', $directory, $file), $content);
    }
70371
public function download($file_name)
	{
		if (!\Entrust::can('download-logs')) {
	        abort(403, 'Unauthorized access - you do not have the necessary permission to download logs.');
	    }

		$disk = Storage::disk('local');

		if ($disk->exists('logs/'.$file_name)) {
			return response()->download(storage_path('logs/'.$file_name));
		}
		else
		{
			abort(404, "The log file doesn't exist.");
		}
	}
933783
private function prepareHeaders($name, StreamInterface $stream, $filename, array &$headers)
    {
        $hasFilename = '0' === $filename || $filename;

        // Set a default content-disposition header if one was not provided
        if (!$this->hasHeader($headers, 'content-disposition')) {
            $headers['Content-Disposition'] = sprintf('form-data; name="%s"', $name);
            if ($hasFilename) {
                $headers['Content-Disposition'] .= sprintf('; filename="%s"', $this->basename($filename));
            }
        }

        // Set a default content-length header if one was not provided
        if (!$this->hasHeader($headers, 'content-length')) {
            if ($length = $stream->getSize()) {
                $headers['Content-Length'] = (string) $length;
            }
        }

        // Set a default Content-Type if one was not provided
        if (!$this->hasHeader($headers, 'content-type') && $hasFilename) {
            if ($type = $this->getMimetypeHelper()->getMimetypeFromFilename($filename)) {
                $headers['Content-Type'] = $type;
            }
        }
    }
146160
public function FileToPDF($path, GrabzItPDFOptions $options = null)
	{
		if (!file_exists($path))
		{
			throw new GrabzItException("File: " . $path . " does not exist", GrabzItException::FILE_NON_EXISTANT_PATH);
		}
		
		$this->HTMLToPDF(file_get_contents($path), $options);
	}
575462
public static function create(string $path, string $asName = null, string $contentType = null): FileDownload
    {
        $self = new static(new File($path));

        if ($asName !== null) {
            $self->setAsName($asName);
        }

        if ($contentType !== null) {
            $self->setContentType($contentType);
        }

        return $self;
    }
856149
public static function includeFileExtension($fileName, $extension)
    {
        $fileExtension = self::getFileExtension($fileName, true);

        /*
         * File has given extension?
         * Nothing to do
         */
        if ($fileExtension === strtolower($extension)) {
            return $fileName;
        }

        return sprintf('%s.%s', $fileName, $extension);
    }
1174244
public function download($file, $name = null, array $headers = array(), $disposition = 'attachment')
	{
		$response = new BinaryFileResponse($file, 200, $headers, true, $disposition);

		if ( ! is_null($name))
		{
			return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name)));
		}

		return $response;
	}
1349400
public function echoPdfContent($content, $filename, $download = false)
    {
        // \MUtil_Echo::track($filename);
        if ($download) {
            // Download & save
			header('Content-Type: application/x-download');
        } else {
            //We send to a browser
            header('Content-Type: application/pdf');
        }
        header('Content-Length: '.strlen($content));
        header('Content-Disposition: inline; filename="'.$filename.'"');
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');

        echo $content;
    }
1096145
public function downloadOnDemand($file, $ext = '')
    {
        // 1. 如果是/开头,认为是当前目录中的素材
        if ($file[0] == '/') {
            $file = ltrim($file, '/');

            return $file;
        }

        // 2. 下载文件到本地固定位置
        return $this->downloadIfRemote($file, $ext, md5($file));
    }
1338916
protected function sendDownloadResponse($file, $extension, array $headers = [])
    {
        return response()->download(
            $file,
            app('scaffold.module')->title().'.'.$extension,
            $headers
        );
    }
247949
public function download($filename = '')
    {
        $filename = $this->formatFilename($filename);
        if ($this->content) {
            $this->printHeader();
            header("Content-Disposition: attachment; filename=\"" . $filename . "\";" );
            ob_clean();
            echo $this->content;
        } elseif ($this->path) {
            $fsize = filesize($this->path);
            $this->printHeader($fsize);
            header("Content-Disposition: attachment; filename=\"" . $filename . "\";" );
            ob_clean();
            readfile($this->path);
        }
    }