Output file to browser

@param string $filename
@param string $format
434915
public static function output($filename='excel', $format='Xlsx')
    {
        $objPhpSpreadsheet = self::validExcelObj();

        // Create Writer first
        $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, $format);

        /**
         * Type Mapping
         */
        $inTypeList = isset(self::$_writerTypeInfo[$format]) ? true : false;
        $extension = ($inTypeList) ? self::$_writerTypeInfo[$format]['extension'] : '';
        $contentType = ($inTypeList) 
            ? self::$_writerTypeInfo[$format]['contentType'] 
            : 'application/octet-stream';

        // Redirect output to a client's web browser
        header("Content-Type: {$contentType}");
        /**
         * @see http://www.rfc-editor.org/rfc/rfc5987.txt
         */
        $filename = rawurlencode($filename);
        header("Content-Disposition: attachment; filename={$filename}{$extension}; filename*=UTF-8''{$filename}{$extension};");
        header("Cache-Control: max-age=0");

        $objWriter->save('php://output');
        exit;
    }
81812
public function save($filename = '', $quality = 100, $format = '')
    {
        if (empty($filename)) {
            $filename = $this->filename;
        }

        if (empty($format)) {
            $format = $this->format;
        }

        $arguments = array($this->image, $filename);

        if (in_array($format, array('jpg', 'jpeg'))) {
            $format = 'jpeg';
            imageinterlace($this->image, true);
            $arguments = array($this->image, $filename, round($quality));
        } else if ($format === 'png') {
            $arguments = array($this->image, $filename, round(9 * $quality / 100));
        }

        return $this->callFunction('image', $format, $arguments);
    }
1296366
protected function createJavascriptsElement(string $path, ?string $format) : string {
        return sprintf($format ?: '<script src="%s"></script>', $this->buildAssetUrl($path));
    }
1349385
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();

        $debug = !$options['compress'];
        $tmp = ltrim($this->_pdf->output($debug));

        header("Cache-Control: private");
        header("Content-Type: application/pdf");
        header("Content-Length: " . mb_strlen($tmp, "8bit"));

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

        echo $tmp;
        flush();
    }
178947
protected function sprintf(string $format, ...$args)
    {
        return $this->output->write(sprintf($format, ...$args), false);
    }
595646
public function setOutputFormat($format = null, $quality = null, $filters = null) {

		if ($format) {
			$format = strtolower($format);

			if (in_array($format, static::$_allowed_formates)) {
				$this->_output_format = $format;

				# fix file extension if this method was called after calling setSaveOptions Method
				if ($this->_save_path) {
					$this->_save_name = preg_replace(
						'/(?<=\.)(?:png|jpeg|jpg|gif)$/i',
						$this->_output_format,
						$this->_save_name
					);

					$this->_save_path = $this->_save_dir . DIRECTORY_SEPARATOR . $this->_save_name;
				}
			}
		}

		// Quality
		$this->_output_options = [];
		if (is_numeric($quality)) {
			// if($format == 'jpg' || $format == 'jpeg')
			// {
			// 	if($quality < 0 || $quality > 100)
			// 		throw new ImageException(__METHOD__ . ' ' . $format . ' quality must be between 0-100');
			// }
			// else if($format == 'png')
			// {
			// 	if($quality < 0 || $quality > 9)
			// 		throw new ImageException(__METHOD__ . ' ' . $format . ' quality must be between 0-9');
			// }

			if ($this->_output_format == 'jpg' || $this->_output_format == 'jpeg') {
				$quality = round($quality * 100 / 100);
			} else if ($this->_output_format == 'png') {
				$quality = round($quality * 9 / 100);
			}

			$this->_output_options[] = $quality;
		}

		// Filters
		if ($filters !== null) {
			// Filters must come after quality
			if (empty($this->_output_options)) {
				$this->_output_options[] = null;
			}

			$this->_output_options[] = $filters;
		}

		return $this;
	}
145184
function write($text,$format='r') {
		$fw=Base::instance();
		$fw->write(
			$this->file,
			date($format).
				(isset($_SERVER['REMOTE_ADDR'])?
					(' ['.$_SERVER['REMOTE_ADDR'].']'):'').' '.
			trim($text).PHP_EOL,
			TRUE
		);
	}
896931
public function getFileOutput($filename)
    {
        if (file_exists($filename)) {
            ob_start();
            include($filename);
            $content = ob_get_contents();
            ob_end_clean();
            $this->logger->info("View parsed - $filename");
        } else {
            $content = "";
        }
        return $content;
    }
771081
protected function streamOutput(ExportableInterface $adminList, $format)
    {
        $response = new StreamedResponse();
        $response->setCallback(function () use ($adminList, $format) {
            $writer = WriterFactory::create($format);
            $writer->openToBrowser('export.'.$format);

            $row = [];
            /** @var Field $column */
            foreach ($adminList->getExportColumns() as $column) {
                $row[] = $this->translator->trans($column->getHeader());
            }
            $writer->addRow($row);

            $iterator = $adminList->getIterator();
            $rows = [];
            foreach ($iterator as $item) {
                if (array_key_exists(0, $item)) {
                    $itemObject = $item[0];
                } else {
                    $itemObject = $item;
                }

                $row = [];
                /** @var Field $column */
                foreach ($adminList->getExportColumns() as $column) {
                    $columnName = $column->getName();
                    $itemHelper = $itemObject;
                    if ($column->hasAlias()) {
                        $itemHelper = $column->getAliasObj($itemObject);
                        $columnName = $column->getColumnName($columnName);
                    }
                    $data = $adminList->getStringValue($itemHelper, $columnName);
                    if (null !== $column->getTemplate()) {
                        if (!$this->renderer->exists($column->getTemplate())) {
                            throw new ExportException('No export template defined for ' . get_class($data), $data);
                        }

                        $data = $this->renderer->render($column->getTemplate(), ['object' => $data]);
                    }

                    $row[] = $data;
                }
                $rows[] = $row;
            }

            $writer->addRows($rows);
            $writer->close();
        });

        return $response;
    }
638854
public function convertTo($filename)
    {
        $outputExtension = pathinfo($filename, PATHINFO_EXTENSION);
        $supportedExtensions = $this->getAllowedConverter($this->extension);

        if (!in_array($outputExtension, $supportedExtensions)) {
            throw new OfficeConverterException("Output extension({$outputExtension}) not supported for input file({$this->basename})");
        }

        $outdir = $this->tempPath;
        $shell = $this->exec($this->makeCommand($outdir, $outputExtension));
        if ($shell['return'] != 0) {
            throw new OfficeConverterException("Convertion Failure! Contact Server Admin.");
        }

        return $this->prepOutput($outdir, $filename, $outputExtension);
    }
729063
function printFormatted(string $format): int {
		$args = func_get_args ();
		$s = call_user_func_array ( 'sprintf', $args );
		return $this->write ( $s );
	}
555582
public function convert($format, $file)
    {
        $file = ltrim($file, '/');
        $this->checkImage($file);

        return $this->wrapper->run("convert", $this->getWebDirectory() . '/' . $file, $this->convertFormat($format), $this->getCacheDirectory() . '/' . $this->pathify($format) . '/' . $file);
    }
814168
public function toString($format = null)
    {
        if ($format) {
            $this->dom->formatOutput = true;
        }
        return $this->dom->saveXML();
    }
999561
public function sendToBrowser($strFilename = '', $strDest = 'I')
    {
        $strFilename = $strFilename ?: $this->buildFilename();

        $this->objPdf->Output($strFilename, $strDest);
    }
566415
function output($format = null, $quality = null) {
        // Determine quality
        $quality = $quality ? : $this->quality;
        // Determine mimetype
        switch (strtolower($format)) {
            case 'gif':
                $mimetype = 'image/gif';
                break;
            case 'jpeg':
            case 'jpg':
                imageinterlace($this->image, true);
                $mimetype = 'image/jpeg';
                break;
            case 'png':
                $mimetype = 'image/png';
                break;
            default:
                $info = (empty($this->imagestring)) ? getimagesize($this->filename) : getimagesizefromstring($this->imagestring);
                $mimetype = $info['mime'];
                unset($info);
                break;
        }
        // Output the image
        header('Content-Type: ' . $mimetype);
        switch ($mimetype) {
            case 'image/gif':
                imagegif($this->image);
                break;
            case 'image/jpeg':
                imageinterlace($this->image, true);
                imagejpeg($this->image, null, round($quality));
                break;
            case 'image/png':
                imagepng($this->image, null, round(9 * $quality / 100));
                break;
            default:
                throw new Exception('Unsupported image format: ' . $this->filename);
                break;
        }
    }
523340
public static function setOutputFormat($format)
    {
        $self = Debugger::getInstance();

        if (!isset($self->_templates[$format])) {
            throw new InvalidArgumentException('Invalid Debugger output format.');
        }
        $self->_outputFormat = $format;
    }
1371434
public function output(Request $request, $template, $output = self::OUTPUT_DOWNLOAD, $format = APIClient::FORMAT_PDF)
    {
        $name = $request->get('name');

        /**
         * Automatically triggers print action once the file is loaded
         */
        $params = [
            'print' => $output === self::OUTPUT_PRINT ? 1 : 0
        ];

        $data = $this->getData();

        try
        {
            /**
             * Set workspace identifier
             */
            \PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));

            $result = \PDFGeneratorAPI::output($template, $data, $format, $name, $params);
        }
        catch(Exception $e)
        {
            return response()->json([
                'error' => $e->getMessage()
            ], $e->getCode());
        }

        $headers = [
            'Content-type' => $result->meta->{'content-type'},
            'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0, max-age=1',
            'Cache' => 'public',
            'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT',
            'Last-Modified' => gmdate('D, d M Y H:i:s').' GMT',
            'Content-Disposition' => 'inline; filename="'.$result->meta->name.'"'
        ];

        if ($output === self::OUTPUT_DOWNLOAD)
        {
            $headers['Content-Description'] = 'File Transfer';
            $headers['Content-Disposition'] = 'attachment; filename="'.$result->meta->name.'"';
            $headers['Content-Transfer-Encoding'] = 'binary';
        }

        return response(base64_decode($result->response), 200, $headers);
    }