【发布时间】:2017-08-06 01:37:08
【问题描述】:
我没有在网上找到好的答案..
我正在使用 symfony2.5 和 php 5.3 并创建一个文件浏览器应用程序。
在应用良好关联的内容类型之前,我想知道文件的扩展名。 mime_content_type 函数已弃用..
这是我的 showAction{},我需要一个函数来测试文件是 excel 文件还是 pdf 文件:
public function showAction($repertoire, $file)
{
$response = new Response();
$response->setContent(file_get_contents(''.$repertoire.'/'.$file.''));
if(file_info($file) == 'application/pdf'){
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-disposition', 'filename='. $file);
return $response;
}else {
$response->headers->set('Content-Type', 'application/application/vnd.ms-excel');
$response->headers->set('Content-disposition', 'filename='. $file);
return $response;
}
}
我从编程开始。你们能帮帮我吗? 非常感谢!
【问题讨论】:
-
必须返回响应对象。
-
我的条件不起作用,已编辑后
-
为什么不测试文件扩展名?
-
应用程序/pdf 不带引号?它不能工作,你应该有语法错误。
-
我需要帮助来创建我的功能/条件家伙
标签: php symfony conditional-statements content-type fileinfo