0
A
回答
1
我的版本是这样的:
/**
* @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;
}
0
$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)
+0
在我的项目中,uploadDir依赖于文件。为了定义路径,我必须在我的对象内部调用方法getUploadDir()。但该方法受到保护。它一定会公开吗?或者,否则,我该怎么办? –
相关问题
- 1. symfony2文件下载管理器
- 2. Symfony2创建并下载zip文件
- 3. 尝试使用Symfony2下载并保存PDF文件
- 4. 使用android下载文件
- 5. 使用wxHTTP下载文件?
- 6. 使用retrofit2下载文件
- 7. 使用qwebkit下载文件
- 8. 使用SMB下载文件
- 9. 使用enyo下载文件
- 10. 使用jQuery下载文件
- 11. 使用python下载文件
- 12. 使用CakePHP下载文件
- 13. 使用AJAX下载文件
- 14. 使用Python下载文件
- 15. 使用dart下载文件
- 16. 下载文件,使用mvc2010
- 17. 使用php下载文件
- 18. 使用PHP下载文件
- 19. 使用php下载文件
- 20. 使用ChromeDriver下载文件
- 21. 下载使用MVC文件
- 22. 使用JSF下载文件?
- 23. 使用C++下载文件
- 24. 使用GZIP下载文件
- 25. 使用PHP下载文件
- 26. 使用硒下载文件
- 27. 使用DCC下载文件
- 28. 使用webclient下载文件
- 29. 使用Python下载文件
- 30. 使用Celerity下载文件
在我的项目中,uploadDir从文件要看。为了定义路径,我必须在我的对象内部调用方法getUploadDir()。但该方法受到保护。它一定会公开吗?或者,否则,我该怎么办? –