- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我设置了一个服务器来为不同域上的网页提供服务(特别是移动设备或 localhost:9000,其中 laravel 在 localhost:8000 上提供服务)。我试图将这些页面上的图像请求返回到我的 laravel 服务器,但我遇到了问题。在论坛帖子中,我认为在请求上设置 header 可以解决问题,但是当我导航到/api/v1/images/default.jpg 时,没有显示默认的猫图像。相反,我得到一个没有图像的框。
现在,图像在我的公共(public)文件夹中,所以如果我浏览到/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'));
// }
});
最佳答案
使用Response::stream
方法来做:
Route::get('/image', function () {
return Response::stream(function () {
$filename = '/path/to/your/image.jpg';
readfile($filename);
}, 200, ['content-type' => 'image/jpeg']);
});
关于php - 如何使用 laravel 4 安静地返回图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25277542/
You can run gdb without printing the front material, which describes gdb's non-warranty, by specifyi
我有一个 ant 构建文件,它通常在完全不同的环境中运行。默认情况下,我正在寻找与使用相同的行为: ant -q 但是,由于某些团队成员的配置不同,因此在每个人的环境中指定 -q 选项并不容易以统一的
我正在使用一个存储库,其中包含许多使用 create-react-app 创建的 Node 包,所有这些都是由 CI 系统构建和测试的。每个包的构建/测试,使用 react-scripts build
我读过有关浮点的内容,并且了解 NaN 可能是由运算产生的。但我无法理解这些到底是什么概念。它们有什么区别? C++编程时可以生成哪一个?作为一名程序员,我可以编写一个导致 sNaN 的程序吗? 最佳
我是一名优秀的程序员,十分优秀!