没有文件被上传!

浏览:1977 发布日期:2019/02/22 分类:求助交流 关键字: thinPHP5.1
thinkphp版本:5.1
集成环境:xampp 64位 3.3.2
php版本:7.2.14 public function editProduct()
    {
        if (request()->isAjax()) {
            $data = input();
            // $f = $_FILES;
            // var_dump($f['pimg']['tmp_name']);
            // die;
            // if ($f['pimg']['tmp_name']) {
                $id = input('?pid') ? input('pid/d') : '';
                $editData = Db::table('product')->where('pid', $id)->find();
                $upload = new Upload();
                $file = request()->file('pimg');
                if ($file) {
                    // 更改图片信息
                    $folder = 'products';
                    $image_path = $upload->upload($file, $folder);
                    // 更新的图片文件插入到upload文件夹中
                    if ($image_path) {
                        // 找到旧文件,删除旧文件
                        if ($editData['pimg']) {
                            if (file_exists('../public' . $editData['pimg'])) {
                                unlink('../public' . $editData['pimg']);
                                // 删除文件
                            }
                        }
                        // 重新写入数据库
                        $data['pimg'] = $image_path;
                    } else {
                        // 图片没有插入到文件夹中
                        $res['msg'] = '上传图片到文件夹中操作失败';
                    }
                } else {
                    // 未更改图片信息
                    if ($editData['pimg']) {
                        $data['pimg'] = $editData['pimg'];
                    }
                    //  else {
                    //     $res['msg'] = '没有图片数据';
                    // }
                }
            // }

            
            $info = Db::table('product')->update($data);
            if ($info) {
                $this->success('数据更新完成', 'index');
            } else {
                $this->error('数据更新失败');
            }
        } else {
            // 读取被修改的原始数据
            $id = input('?id') ? input('id/d') : '';
            // dump($id);
            //     die;
            $editData = Db::table('product')
                ->where('pid', $id)
                ->find();
            $this->assign('product', $editData);
            return view('editProduct');
        }
    }
出现下列错误
[0] Exception in Request.php line 1261
没有文件被上传!
2 => 'upload File size exceeds the maximum value',
3 => 'only the portion of file is uploaded',
4 => 'no file to uploaded',
6 => 'upload temp dir not found',
7 => 'file write error',
];

$msg = $fileUploadErrors[$error];

throw new Exception($msg);
}

/**
* 获取环境变量
* @access public
* @param string $name 数据名称
* @param string $default 默认值
* @return mixed
*/
Call Stack
in Request.php line 1261
at Request->throwUploadFileError(4) in Request.php line 1235
at Request->dealUploadFile(['pimg' => ['name' => '', 'type' => '', 'tmp_name' => '', ...]], 'pimg') in Request.php line 1187
at Request->file('pimg') in Product.php line 72
at Product->editProduct()
at ReflectionMethod->invokeArgs(object(Product), []) in Container.php line 395
at Container->invokeReflectMethod(object(Product), object(ReflectionMethod), ['pname' => 'gdfsgfdgdf', 'pid' => '42', 'pcontent' => 'fsadfasdf', ...]) in Module.php line 132
at Module->think\route\dispatch\{closure}(object(Request), object(Closure), null)
at call_user_func_array(object(Closure), [object(Request), object(Closure), null]) in Middleware.php line 185
at Middleware->think\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Middleware.php line 130
at Middleware->dispatch(object(Request), 'controller') in Module.php line 137
at Module->exec() in Dispatch.php line 168
at Dispatch->run() in App.php line 432
at App->think\{closure}(object(Request), object(Closure), null)
at call_user_func_array(object(Closure), [object(Request), object(Closure), null]) in Middleware.php line 185
at Middleware->think\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Middleware.php line 130
at Middleware->dispatch(object(Request)) in App.php line 435
at App->run() in index.php line 21
最佳答案
评论() 相关
后面还有条评论,点击查看>>