Laravel:如何在多个数据库字段中上传多个图像文件?

时间:2017-01-05 16:36:09

标签: php laravel laravel-5 multiple-file-upload

我想在数据库中上传多个图像文件.. 这是视图部分:

<input type="file" name="photo[]" >
<input type="file" name="photo[]" >
<input type="file" name="photo[]" >

我想将路径存储到数据库中的不同字段中。

控制器代码:

 public function store(Request $request)
    {


        $product = new Product();
        $product->name = $request->Input(['name']);
        $product->description = $request->Input(['description']);
    $files = Input::file('photo');
            $names = [];

            foreach ($files as $file) {
                $names[] = $file->getClientOriginalExtension();
            }
                $imageName1 = time().'.'.$names[0];
                $imageName2 = time().'.'.$names[1];
                $imageName3 = time().'.'.$names[2];         
            $product->primary_image = $imageName1;
                    $file->move('images/', $imageName1);
            $product->optional_image_one = $imageName2;
                    $file->move('images/', $imageName2);
            $product->optional_image_two = $imageName3;
                    $file->move('images/', $imageName3);
        $product->price = $request->Input(['price']);
        $product->save();

        return Redirect::to('product');

    }

我收到以下错误:

FileException in UploadedFile.php line 235:
The file "3.jpg" was not uploaded due to an unknown error.

任何人都可以分配到对象中的错误是什么?还是解决方案..

0 个答案:

没有答案