更新时间:2023-11-17 08:10:40
问题已解决.原来是一个包含空格的php类.我猜这弄乱了标题.
Problem solved. Turned out to be a included php class with whitespace in it. This messed up the headers i guess.
通过创建一个新的空项目来解决,并逐步进行操作,直到出现不良类为止.
Solved by creating a new, empty project and include step by step until the bad class showed.
在Slim函数中设置标题的有效解决方案;
Working solution for setting headers inside a Slim function;
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/foo', function () use ($app) {
$app->response->headers->set('Content-Type', "application/pdf");
$app->response->setBody("foo");
});
$app->run();
?>
已更新:这是我用来让用户下载PDF的标题:
Updated: This is the headers I use to let a user download a PDF:
$app->response->headers->set('Content-Type', $f->type);
$app->response->headers->set('Pragma', "public");
$app->response->headers->set('Content-disposition:', 'attachment; filename=' . $f->name);
$app->response->headers->set('Content-Transfer-Encoding', 'binary');
$app->response->headers->set('Content-Length', $f->size);
$app->response->setBody($f->data);