图像会像tmp文件一样保存在公用文件夹中

时间:2019-07-28 16:20:48

标签: laravel eloquent laravel-5.8

我试图在db中添加数据,但是图像保存为tmp文件,m将这些图片存储在ecommmerce \ public \ images \ backend_images \ category_images中,而这些真实图片未保存,而是将其真实姓名保存在db中,而是保存在文件夹像这样:https://ibb.co/CHXTm3j ..任何解决方案。这是我的代码:

存储功能:

    $category = new Category;
    $category->category_name = $request->category_name;
    $category->category_description = $request->category_description;
    $category->category_slug = $request->category_slug;
    $path = $request->file('category_image');
    $image = $path->getClientOriginalName();
    $path->move(public_path('images/backend_images/category_images'));
    $category->category_image = $image;
    $category->save();

1 个答案:

答案 0 :(得分:0)

因为那里缺少文件名的参数。您移动原始文件的功能应为:

$path->move(public_path('images/backend_images/category_images'), $image);

如果不提供该参数,则默认值为文件的临时名称,而不是原始名称。