无法使用Intervention库将图像数据写入laravel中的路径

use*_*153 9 php laravel

我正在使用Laravel 4.2和Intervention库,我不知道为什么当其他一切看起来正确时我会遇到这个问题.这是代码:

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));
    }
});
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

干预\ Image\Exception\NotWritableException无法将图像数据写入路径(C:\ xampp\htdocs\jacars_project\public/images/cars/2014-08-26-03:41:39-icon_2034.png).

在此先感谢帮助我解决问题

ako*_*ako 15

您可以检查目录是否存在,如果没有这样的目录,则创建它:

        if (!file_exists($save_path)) {
            mkdir($save_path, 666, true);
        }
Run Code Online (Sandbox Code Playgroud)


The*_*pha 8

只需改变这个:

$path = public_path('images/cars/'.$filename);
Run Code Online (Sandbox Code Playgroud)

对此:

$path = 'images/cars/' . $filename;
Run Code Online (Sandbox Code Playgroud)

此外,确保目标path/location是可写的,具有写入权限.

  • 如何确保路径/位置可写并具有写权限? (3认同)
  • Windows 8我正在运行 (3认同)