tp框架之文件上传
控制器
function wenjian() { if(empty($_FILES)) { $this->display(); } else { $u = new \Think\Upload();// 实例化上传类 $u->maxSize=1024000 ;// 设置附件上传大小 $u->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $u->rootPath ="./Public/"; //根路径 $u->savePath="Uploads/"; // 设置附件上传目录 $u->saveName = 'time'; // 上传文件 $info = $u->upload(); var_dump($info); } }
显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="__ACTION__" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="上传" />
</form>
</body>
</html>