我的控制器看起来像这样:
public function download($filepath)
{
// Generate response
$response = new Response();
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', mime_content_type($filepath));
$response->headers->set('Content-Disposition', 'attachment; filepath="' . basename($filepath) . '";');
$response->headers->set('Content-length', filesize($filepath));
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(readfile($filepath));
}
将文件路径传递给它会导致以下错误消息:
Call to undefined function MyBundle\Controller\mime_content_type()
我该如何解决这个问题?
use
添加了这个类,但是当我想通过$oFile = new File($filepath)
创建一个文件实例时,PHPStorm告诉我这个类未定义。为什么?我忘了什么? - Max{% set filepath = asset('bundles/mybundle/files/example.pdf') %} <a href="{{ url('_route_bundle_download', { 'filepath': filepath|url_encode }) }}"> <button>Download</button> </a>
有什么问题吗? - Max