无法使用Intervention库将图像数据写入laravel中的路径 [英] can't write image data to path in laravel using the Intervention library
问题描述
我正在将Laravel 4.2与Intervention库一起使用,并且我不确定在其他一切似乎都正确的情况下为什么会遇到此问题.这是代码:
I am using Laravel 4.2 with the Intervention library,and I am not sure why I am getting this problem when everything else seems to be right. here is the code:
Route::post('test',function()
{
// check if files was sent
if(Input::hasFile('file'))
{
$image = Input::file('file');
$filename = date('Y-m-d-H:i:s').'-'.$image->getClientOriginalName();
$path = public_path('images/cars/'.$filename);
Image::make($image->getRealPath())->resize(468,249)->save($path);
} else {
return Response::json(array('test'=>false));
}
});
我收到的错误是:
干预\图像\异常\ NotWritableException无法将图像数据写入路径(C:\ xampp \ htdocs \ jacars_project \ public/images/cars/2014-08-26-03:41:39-icon_2034.png).
Intervention \ Image \ Exception \ NotWritableException Can't write image data to path (C:\xampp\htdocs\jacars_project\public/images/cars/2014-08-26-03:41:39-icon_2034.png).
预先感谢您帮助我解决问题
Thanks in advance in helping me solve the problem
推荐答案
您可以检查目录是否存在,如果没有这样的目录,则可以创建它:
you can check for directory existence , if there is no such directory then create it :
if (!file_exists($save_path)) {
mkdir($save_path, 666, true);
}
这篇关于无法使用Intervention库将图像数据写入laravel中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!