내 프로젝트에는 파일을 업로드 할 수있는 가능성이 있습니다. 나는이 책을 Symfony2 documentation으로 발전 시켰습니다.Symfony2로 파일 다운로드
컨트롤러에서 해당 파일을 다운로드 할 수있는 동작을 생성하지 못했습니다.
어떻게하면됩니까?
내 프로젝트에는 파일을 업로드 할 수있는 가능성이 있습니다. 나는이 책을 Symfony2 documentation으로 발전 시켰습니다.Symfony2로 파일 다운로드
컨트롤러에서 해당 파일을 다운로드 할 수있는 동작을 생성하지 못했습니다.
어떻게하면됩니까?
내 버전은 다음과 같습니다
/**
* @Route("/download/{file_id}", name="download_file")
*/
public function downloadAction($file_id)
{
// get your filepath from db somehow by file_id or whatever
$path = ...
$file = getimagesize($path);
$response = new Response();
$response->setContent(file_get_contents($path));
$response->headers->set('Content-Type', $file['mime']);
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
}
$response=new Response();
$response->setContent(file_get_contents($localFilePath));
강력하게 당신이 사용할 수 있습니다 다운로드의 경우 : 내 프로젝트에서
$file_url = 'http://www.myremoteserver.com/file.exe';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url); // do the double-download-dance (dirty but worky)
내 프로젝트에서 uploadDir은 파일에 따라 다릅니다. 경로를 정의하려면 내 객체 내부에 getUploadDir() 메서드를 호출해야합니다. 그러나이 방법은 보호되어 있습니다. 공개로 설정해야합니까? 그렇지 않으면 어떻게 할 수 있습니까? –
에서, uploadDir 파일에서 따라 달라집니다. 경로를 정의하려면 내 객체 내부에 getUploadDir() 메서드를 호출해야합니다. 그러나이 방법은 보호되어 있습니다. 공개로 설정해야합니까? 그렇지 않으면 어떻게 할 수 있습니까? –