Send rendering to browser with a 'download file' prompt

@param string $filename without path & without format extension
183316
public function sendToBrowserDownload($filename)
    {
        ReportRenderer::sendToBrowser(
            $filename,
            ReportRenderer::CSV_FORMAT,
            "text/" . ReportRenderer::CSV_FORMAT,
            $this->getRenderedReport()
        );
    }
840412
final public function saveImage($filename)
	{
		$extension = pathinfo($filename, PATHINFO_EXTENSION);

		if (! is_string($extension)) {
			$extension = image_type_to_extension($this->_image_type);
			$filename .= ".{$extension}";
		}

		switch(strtolower($extension))
		{
			case 'jpeg':
			case 'jpg':
				return $this->imageJPEG($filename);
				break;

			case 'png':
				return $this->imagePNG($filename);
				break;

			case 'gif':
				return $this->imageGIF($filename);

			default:
				trigger_error('Invalid extension or not an image', E_USER_WARNING);
				return false;
		}
	}
1357065
public function download($fileName)
    {
        header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
        header("Content-Disposition: attachment; filename={$fileName}");

        echo $this->createOutputContents(
                        $this->header,
                        $this->delimiter4Csv,
                        $this->enclosure,
                        $this->toConvert
                    );
    }
1223206
public function stream($filename = "document.pdf", $options = array())
    {
        if (headers_sent()) {
            die("Unable to stream pdf: headers already sent");
        }

        if (!isset($options["compress"])) $options["compress"] = true;
        if (!isset($options["Attachment"])) $options["Attachment"] = true;

        $this->_add_page_text();

        if ($options["compress"]) {
            $this->_pdf->set_value("compress", 6);
        } else {
            $this->_pdf->set_value("compress", 0);
        }

        $this->_close();

        $data = "";

        if (self::$IN_MEMORY) {
            $data = $this->_pdf->get_buffer();
            $size = mb_strlen($data, "8bit");
        } else {
            $size = filesize($this->_file);
        }

        header("Cache-Control: private");
        header("Content-Type: application/pdf");
        header("Content-Length: " . $size);

        $filename = str_replace(array("\n", "'"), "", basename($filename, ".pdf")) . ".pdf";
        $attachment = $options["Attachment"] ? "attachment" : "inline";
        header(Helpers::buildContentDispositionHeader($attachment, $filename));

        if (self::$IN_MEMORY) {
            echo $data;
        } else {
            // Chunked readfile()
            $chunk = (1 << 21); // 2 MB
            $fh = fopen($this->_file, "rb");
            if (!$fh) {
                throw new Exception("Unable to load temporary PDF file: " . $this->_file);
            }

            while (!feof($fh)) {
                echo fread($fh, $chunk);
            }
            fclose($fh);

            //debugpng
            if ($this->_dompdf->getOptions()->getDebugPng()) {
                print '[pdflib stream unlink ' . $this->_file . ']';
            }
            if (!$this->_dompdf->getOptions()->getDebugKeepTemp()) {
                unlink($this->_file);
            }
            $this->_file = null;
            unset($this->_file);
        }

        flush();
    }
1022724
public function sendToBrowserInline($filename)
    {
        ReportRenderer::sendToBrowser(
            $filename,
            ReportRenderer::CSV_FORMAT,
            "application/" . ReportRenderer::CSV_FORMAT,
            $this->getRenderedReport()
        );
    }
977189
public function outputWithHeaders($filename = 'output.xls')
    {
        \header("Expires: " . date("r", 0));
        \header("Last-Modified: " . gmdate("r") . " GMT");
        \header("Content-Type: application/x-msexcel");
        \header("Content-Disposition: attachment; filename=" . $filename);
        echo $this->__toString();
    }
10636
private function openStream($filename)
    {
        if (!file_exists($filename)) {
            throw new ExtensionException(sprintf('File path (%s) doesn\'t exist', $filename));
        }
        
        if (!is_readable($filename)) {
            throw new ExtensionException(sprintf('File path (%s) doesn\'t readable', $filename));
        }
        
        return fopen($filename, 'a+');
    }
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);
        }
    }
1084738
private function _downloadFile($url, $filename)
    {
        $dirname = dirname($filename);
        if (! is_dir($dirname)) {
            mkdir($dirname, 0777, true);
        }
        saveUrl($url, $filename);
    }
86601
final public function setDestinationFilename(string $filename)
    {
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        if (empty($extension) && !empty($this->uploadFile->getExtension())) {
            $filename .= '.' . $this->uploadFile->getExtension();
        }
        $this->destinationFilename = $filename;
    }
895146
public function render($fileName, $data = [])
    {
        $content = $this->renderParticle($fileName, $data);
        if ($this->layout) {
            ob_start();
            ob_implicit_flush(false);
            $layout = $this->getLayoutPath();
            require $layout;
            return ob_get_clean();
        } else {
            return $content;
        }
    }
1085816
public function _savePageSource($filename)
    {
        if (!isset($this->webDriver)) {
            $this->debug('WebDriver::_savePageSource method has been called when webDriver is not set');
            return;
        }
        try {
            file_put_contents($filename, $this->webDriver->getPageSource());
        } catch (\Exception $e) {
            $this->debug('Unable to retrieve source page from Selenium : ' . $e->getMessage());
        }
    }
276151
public function exportToFile(string $filename)
    {
        if (($p = strrpos($filename, DIRECTORY_SEPARATOR)) >= 0) {
            $path = substr($filename, 0, $p);
            $name = substr($filename, $p + 1);

            if (strlen($path) > 0 && !is_dir($path)) {
                mkdir($path, 0755, true);
            }
        }

        if (($handler = fopen($filename, 'w'))) {
            fwrite($handler, $this->code);
            fclose($handler);
        }
    }
1031605
public function setDownload($filename = false) {
        $h = "attachment;";
        if ($filename) {
            $h .= "filename='" . $filename . "'";
        }
        $this['response']->setHeader("Content-Disposition", $h);
    }
885301
public function force($bytes, $filename, Zend_Controller_Response_Abstract $response) {
        if (!strlen($bytes)) {
            $response->setBody('Sorry, we could not find the requested file.');
        } else {
            // Disable view and layout rendering
            Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->setNoRender();
            Zend_Controller_Action_HelperBroker::getExistingHelper('layout')->disableLayout();
            
            // Process the download
            $this->_setHeaders($bytes, $filename, $response);
            $response->setBody($bytes);
        }
    }
1208069
static public function open($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;
			case IMAGETYPE_XBM:
				$image = imagecreatefromxbm($filename);
				break;
			case IMAGETYPE_XPM:
				$image = imagecreatefromxpm($filename);
				break;
			case IMAGETYPE_WEBP:
				$image = imagecreatefromwebp($filename);
				break;
			default:
				throw new Exception('Unknown image format!');
				break;
		}
		imagealphablending($image, false);
		imagesavealpha($image, true);

		return new self($image);
	}
179802
public function setFileName($fileName)
    {
        $this->fileName = $fileName;
        $this->headers->add(array('Content-Disposition' => 'attachment; filename="' . $this->fileName . '"'));
        return $this;
    }