Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问图片上传的方法怎么写才能实现多图片同时选择上传 #3

Open
BEIBEI123 opened this issue Sep 18, 2018 · 2 comments

Comments

@BEIBEI123
Copy link

BEIBEI123 commented Sep 18, 2018

目前我的写法是这样的,但是只支持单文件上传

    public function wang_upload(Request $request){
        if ($request->hasFile('wangEditorH5File') && $request->file('wangEditorH5File')->isValid()) {
            $file = $request->file('wangEditorH5File');
            $save=array();
            $result = '/storage/'.Storage::disk("admin")->putFile("editor", $file);
            $save[]=$result;
            echo json_encode(array('errno'=>0,'data'=>$save));
        } else {
            echo json_encode(array('errno'=>1,'data'=>array(),'info'=>'no picture'));
        }
    }
@z-song
Copy link
Member

z-song commented Sep 18, 2018

$request->allFiles()获取所有上传文件对象

@BEIBEI123
Copy link
Author

BEIBEI123 commented Sep 18, 2018

可以了,谢谢,贴出了方便大家使用:

    public function wang_upload(Request $request){
        $save=array();
        $all_file=$request->allFiles();
        foreach ($all_file['wangEditorH5File'] as $key => $value) {
            if ($value->isValid()) {
                $result = '/storage/'.Storage::disk("admin")->putFile("editor", $value);
                $save[]=$result;
            }
        }
        echo json_encode(array('errno'=>0,'data'=>$save));
    }

配置方法:

        'wang-editor' => [
            // 如果要关掉这个扩展,设置为false
            'enable' => true,
            // 编辑器的配置
            'config' => [
                'uploadImgServer' => '/api/wang_upload',
                'uploadFileName'  => 'wangEditorH5File[]'
            ]
        ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants