//html部分示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://www.shizhanzhe.com/js/jquery1.42.min.js"></script>
</head>
<body>
<form action="/index.php/index/index/gaoUpload" method="post" enctype="multipart/form-data">
<input type="text" name="gaoname" value="" placeholder="图片名称,支持字母或数字"><br/>
<input type="text" name="gaourl" value="" placeholder="图片链接"><br/>
<input type="file" name="gaopic" value=""><br/>
<input type="submit" value="上传">
</form>
</body>
</html>
//页面渲染
public function gaoPic(){
return $this->fetch();
}
//数据提交方法
public function gaoUpload(){
$request = request();//think助手函数
$data_get = $request->param();//获取get与post数据
$file = request()->file('gaopic');
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/gao');
if($info){
//组装新数据
$gao_data = array(
'gaoname'=>$data_get['gaoname'],
'gaopic'=>$info->getSaveName(),
'gaourl'=>$data_get['gaourl']
);
//获取文件的信息
$gao_json = file_get_contents('gaopic.ini');
$gao_arr = json_decode($gao_json,true);
$gao_arr[] = $gao_data;
$gao_content = json_encode($gao_arr);
//创建ini文件
$gao_file = fopen("gaopic.ini","w+") or die("Unable to open file!");
//将内容写入文件
fwrite($gao_file, $gao_content);
//关闭文件
fclose($gao_file);
}
}