TP文件上传

一、单文件上传

<form action="__ACTION__" enctype="multipart/form-data" method="post" >
	<input type="text" name="name" />
	<input type="file" name="photo" />
	<input type="submit" value="提交" >
</form>

 

<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
	public function login(){
		if(!empty($_POST)){
			
			$upd = new \Think\Upload();
			$upd->rootPath = "./Public/";
			$upd->savePath = "./upload/";
			$info = $upd->upload();
			
			
		}else{
			$this->show();
		}
	}
	
}

提交以后文件里多了一个文件夹

 

二、多文件上传

<form action="__ACTION__" enctype="multipart/form-data" method="post" >
	<input type="text" name="name" />
	<input type="file" name="photo" />
	<input type="file" name="photo1" />
	<input type="submit" value="提交" >
</form>

 

<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
	public function login(){
		if(!empty($_POST)){
			
			$upd = new \Think\Upload();
			$upd->rootPath = "./Public/";
			$upd->savePath = "./upload/";
			$info = $upd->upload();
			var_dump($info);
			
			
		}else{
			$this->show();
		}
	}
	
}

 上传两张图片

 

posted @ 2018-03-18 16:36  navyyouth  阅读(229)  评论(0编辑  收藏  举报