【问题标题】:The file "image.jpg" was not uploaded due to an unknown error in laravel while uploading two images由于 laravel 在上传两张图片时出现未知错误,文件“image.jpg”未上传
【发布时间】:2018-09-20 04:37:27
【问题描述】:

我在 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);
    }

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

【问题讨论】:

  • image_2 代码中的变量名错误。

标签: laravel laravel-5


【解决方案1】:

图片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);
}

【讨论】:

  • 到期 $featured_1。
猜你喜欢
  • 2017-12-11
  • 1970-01-01
  • 2020-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多