上传图片的HTML结构:
<form action="{:U('Config/addImg')}" enctype="multipart/form-data" method="post" > <input type="text" name="name" /><br> <input type="file" name="photo[]" /><br> <input type="submit" value="提交" > </form>
上传PHP示例:
public function addImg(){
$upload = new ThinkUpload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = "./Application/uploads/"; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
if(!$info){
json_encode("上传失败");die;
};
$path = "Application/uploads/".$info['file']['savepath'].$info['file']['savename'];
echo $path;
}