웹상에서 좋은 답변을 찾지 못했습니다.쉬운 조건문 파일 정보
저는 symfony2.5 및 php 5.3을 사용하고 있으며 파일 탐색기 응용 프로그램을 만들고 있습니다.
좋은 연관 콘텐츠 유형을 적용하기 전에 파일의 확장자를 알고 싶습니다.
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;
}
}
내가 프로그래밍을 시작 해요 : mime_content_type 기능이
가 여기 내 showAction {}이다 .. 사용되지 않습니다, 난 파일이 엑셀 하나 또는 PDF 파일의 경우 테스트하는 기능이 필요합니다. 너희들 나를 도울 수 있니? 감사합니다.
당신은 응답 객체를 반환해야합니다 당신은 다음,
finfo
리소스를 만들과 같이, 파일을 검사하기 위해 해당 자원을 사용해야합니다. – COil내 상태가 작동하지 않아 게시 된 게시물 –
파일 확장명을 테스트하지 않는 이유는 무엇입니까? – Edwin