【发布时间】:2014-10-06 07:17:52
【问题描述】:
我设置了一个服务器来提供不同域上的网页(特别是移动设备或 localhost:9000,其中 laravel 在 localhost:8000 上提供服务)。我正在尝试将这些页面上的图像请求返回到我的 laravel 服务器,但我遇到了问题。从论坛帖子中,我认为在请求上设置标头可以解决问题,但是当我导航到 /api/v1/images/default.jpg 时,没有显示默认的猫图像。相反,我得到一个没有图像的盒子。
现在,图像在我的公用文件夹中,所以如果我浏览到 /public/images/default.jpg 我确实看到了我的猫图像,但我宁愿在我的 /api/v1/... 路由中提供图像.
Route::get('images/{imageName}', function($imageName){
$img = 'public/images/' . $imageName;
// return $img;
echo $img . "\n\n";
if(File::exists($img)) {
// return "true";
// return Response::make($img, 200, array('content-type' => 'image/jpg'));
// return Response::download($img, $imageName);
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: inline; filename=\"".$imageName."\"");
header("Content-Type: image/jpg");
header("Content-Transfer-Encoding: binary");
//stream the file out
readfile($img);
exit;
} else {
return "false";
}
return $img;
// return File::exists($img);
// return File::isFile('/images/' . $imageName);
// return $imageName;
// if(File::isFile('images/' + $imageName)){
// return Response::make('images/' + $imageName, 200, array('content-type' => 'image/jpg'));
// }
});
【问题讨论】:
标签: php laravel laravel-4 laravel-routing