Php 在同一请求中发送HTML和PDF文件是否正确?

Php 在同一请求中发送HTML和PDF文件是否正确?,php,http,http-headers,Php,Http,Http Headers,我必须向用户发送一个PDF,但是这个PDF是由从PHP(服务器端)执行的命令行工具生成的。当用户单击链接时,将执行以下操作: window.open($(this).attr('href'), "mywindow", "height=600,width=600,menubar=0,location=0,status=0,toolbar=0"); 新窗口由PHP生成: <?php ob_start(); ?> Web page contents to be

我必须向用户发送一个PDF,但是这个PDF是由从PHP(服务器端)执行的命令行工具生成的。当用户单击链接时,将执行以下操作:

window.open($(this).attr('href'), "mywindow",
            "height=600,width=600,menubar=0,location=0,status=0,toolbar=0");
新窗口由PHP生成:

<?php
ob_start();
?>
 Web page contents to be printed
<?php
$content = ob_get_contents();
ob_end_flush();

$input = "/tmp/input.html";
$output = "/tmp/output.pdf";

file_put_contents($input, $content);
create_pdf($input, $output);

$state = filesize($output);
if ($state !== FALSE && $state != 0) {
    header('Content-Type: application/pdf');
    header('Content-Disposition: inline; filename=file.pdf');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($output));

    ob_clean();
    flush();
    @readfile($output);
}

unlink($input);
unlink($output);

要打印的网页内容

您可以从任何URL发送您喜欢的任何内容,前提是返回给客户端的标题适合该内容。

是的,问题是我发送的标题和内容是否合适:)