PHPCMS V9手机移动端(支持单图和多图)图片上传,(PHPCMS V9前台使用layui的上传组件代替默认的SWFupload上传图片)

默认phpcms的上传 图片使用的是swfupload,导致手机移动端上传图片无法使用。这里我们使用layui的上传组件来使其支持手机移动端(支持单图和多图)图片上传,效果图如下:
PHPCMS V9手机移动端(支持单图和多图)图片上传,(PHPCMS V9前台使用layui的上传组件代替默认的SWFupload上传图片)_第1张图片

PHPCMS V9手机移动端(支持单图和多图)图片上传,(PHPCMS V9前台使用layui的上传组件代替默认的SWFupload上传图片)_第2张图片
 
实现步骤:
一、 打开phpcms\modules\attachment\attachments.php文件,新增如下函数:

public function imgupload() {
		pc_base::load_sys_class('attachment','',0);
		$module = trim($_GET['module']);
		$catid = intval($_GET['catid']);
		$siteid = $this->get_siteid();
		$site_setting = get_site_setting($siteid);
		$site_allowext = $site_setting['upload_allowext'];
		$attachment = new attachment($module,$catid,$siteid);
		$a = $attachment->upload('file',$site_allowext);
		if($a){
            $result['code'] = 0;
            $result['msg'] = '图片上传成功!';
            $result['src'] = $this->upload_url.$attachment->uploadedfiles[0]['filepath'];
            //return $result;
            exit(json_encode($result));
        }else{
            // 上传失败获取错误信息
            $result['code'] = 1;
            $result['msg'] = '图片上传失败!';
            //return $result;
            exit(json_encode($result));
        }
	}

二、上传表单的模板(模板中需要引入layui.css和layui.js)如下:

你可能感兴趣的:(PHPCMS)