dtzd65908 2017-01-05 16:36
浏览 75

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

I want to upload multiple image files in database .. Here is the view part :

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

And I want to store the path into different field in database..

controller code:

 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');

    }

I got the following Error:

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

Can anyone what's the error for assigning into object? or solution please ..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)