layui+tp5.1.31 图片上传提示模块不存在404

浏览:1350 发布日期:2019/04/10 分类:求助交流 关键字: 上传
这是html上传方法upload.render({
            elem: '#cover',
            url: '{:url("index/upload/uploadfile")}',
            accept: 'file',
            exts: 'jpg|jpeg|png|gif',
            acceptMime: 'image/jpg, image/jpeg, image/png, image/gif',
            data: {
                dir: 'cover'
            },
            before: function(){
                layer.msg('上传中...', {
                    time: 0 //2秒关闭(如果不配置,默认是3秒)
                });
            },
            done: function(res){
                layer.closeAll();
                if(res.status == '-1'){
                    layer.alert(res.msg);
                    return;
                }
                $('.cover').attr('href', res.savename).find('span').text('查看');
                $('input[name=cover]').val(res.savename);
            },
            
            error: function(index, upload, error){
                layer.closeAll();
                layer.msg('上传失败,请重试');
            }
        });
这是上传php代码<?php
/*
 # 图片上传
 */

namespace app\index\controller;

use think\Controller;

class Upload extends Controller{
    
    /**
     * 上传文件
     */
    public function uploadfile(){
        // 获取表单上传文件 例如上传了001.jpg
        $file = $request->file('file');
        $dir = $request->param('dir');
        if($dir == ''){
            $rs['msg'] = '请设置上传目录';
            $rs['status'] = -1;
            return json($rs);
        }

        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move('./public/uploads/' . $dir);

        if($info){
            // 成功上传后 获取上传信息
            $rs['savename'] = '/uploads/' .$dir .'/'. str_replace("\\","/", $info->getSavename());
            $rs['filename'] = $info->getFilename();
            $rs['extension'] = $info->getExtension();
            $rs['status'] = 1;
            return json($rs);
        }else{

            $rs['msg'] = $info->getError();
            $rs['status'] = -1;
            return json($rs);
        }
    }

}
报错信息div class="info">
                <div>
                    <h2>[0] <abbr title="think\exception\HttpException">HttpException</abbr> in <a class="toggle" title="/home/tianyish/public_html/thinkphp/library/think/route/dispatch/Module.php line 63">Module.php line 63</a></h2>
                </div>
                <div><h1>模块不存在:upload</h1></div>
            </div>
最佳答案
评论( 相关
后面还有条评论,点击查看>>