后台页面的图片上传

图片上传的前端页面

此页面是由layui框架中调用上传方法,方法如下:

public function singleupload(){
	    if(!empty($_FILES['upfile']['tmp_name'][0])){
                $config = array(
                    'rootPath'      =>  './', //保存根路径
			        'savePath'      =>  'uploads/', //保存路径
					'maxSize'       =>  4190000,
					'exts'          =>  array('jpg','gif','png','jpeg'), //允许上传的文件后缀
					'subName'       =>  array('date', 'Y-m'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
                );
                //附件被上传到路径:根目录/保存目录路径/创建日期目录
               $upload = new \Think\Upload($config);
		       $filePaths=$config['rootPath'].$config['savePath'].$config['subName'];
			   if (!file_exists($filePaths)) {
                   mkdir($filePaths, 0777, true);
               }
               $z = $upload -> uploadOne($_FILES['upfile']);
               if (!$z){
				   $error_msg=$upload->getError();
				   $this->ajaxReturn(array("status"=>0,"msg"=>$error_msg));
		          }else{
			       $imageurl=$z['savepath'].$z['savename'];
                   $this->ajaxReturn(array("status"=>1,"msg"=>$imageurl));
		       }
        }
   }

你可能感兴趣的:(学习起步)