由于上传两张图片时laravel中发生未知错误,因此未上传“ image.jpg”文件

时间:2018-09-20 04:37:27

标签: laravel laravel-5

我在Laravel中上传多个图像时遇到问题。当我浏览并选择一个图像时,它工作正常。但是,当我浏览并选择两个图像时,出现错误“由于未知错误,未上传文件“ image.jpg”。

ImageController.php

$featured = $request->file('image');
    $path=null;
    if(isset($featured)){
        $path = "images/";
        $year_folder = $path . date("Y");
        $month_folder = $year_folder . '/' . date("m");
            $path = "images/";
            $image_name = time().'.'.$featured->getClientOriginalName();
            $path = $month_folder . '/' . $image_name;
            $featured->move(public_path($month_folder), $image_name);
    }

    $featured_1 = $request->file('image_1');
    $path_1=null;
    if(isset($featured_1)){
        $path_1 = "images/";
        $year_folder = $path . date("Y");
        $month_folder = $year_folder . '/' . date("m");
            $path_1 = "images/";
            $image_name = time().'.'.$featured->getClientOriginalName();
            $path_1 = $month_folder . '/' . $image_name;
            $featured->move(public_path($month_folder), $image_name);
    }

如果我一次选择一个图像,但是同时选择两个图像时出现错误,此代码可以正常工作。

1 个答案:

答案 0 :(得分:0)

上传图片2的代码:

$featured_1 = $request->file('image_1');
$path_1     = null;
if (isset($featured_1)) {
    $path_1       = "images/";
    $year_folder  = $path . date("Y");
    $month_folder = $year_folder . '/' . date("m");
    $path_1       = "images/";
    $image_name_2 = time() . '.' . $featured_1->getClientOriginalName();
    $path_1       = $month_folder . '/' . $image_name_2;
    $featured->move(public_path($month_folder), $image_name_2);
}