Php 在laravel中下载图像?

Php 在laravel中下载图像?,php,laravel,laravel-4,Php,Laravel,Laravel 4,如何在laravel中下载图像 $file= "http://localhost/laravel/public/galleries/image.png"; $headers = array('Content-Type: image/png'); return Response::download($file, 'download_image.png',$headers); 我无法打开此映像。需要通过文件系统引用该文件 Windows示例:C:\inetpub\wwwroot\app\files

如何在laravel中下载图像

$file= "http://localhost/laravel/public/galleries/image.png";
$headers = array('Content-Type: image/png');
return Response::download($file, 'download_image.png',$headers);

我无法打开此映像。

需要通过文件系统引用该文件

Windows示例:C:\inetpub\wwwroot\app\files\image.png

然后在控制器中:

return Response::download('C:\inetpub\wwwroot\app\files\image.png');

那么你得到了什么样的输出呢?您是否遇到任何错误?请尝试以下路径
“http://localhost/laravel/galleries/image.png“
如果我试图打开下载的图像,它会显示损坏的图像。然后可能会检查图像是否确实损坏,是否是错误的MIME类型(尽管它被设置为.png,但可能是其他类型),或者检查文件权限。
$file
应该是本地文件(“C:/webserver/htdocs/laravel/public/…”,而不是HTTP资源)。用记事本打开文件并显示内容。它很可能是调试输出。您可能会向我们显示一个“未找到文件”异常。