目录
时间函数
<?php
$time=date('Y-m-d h:i:s');//年-月-日 小时:分:秒
var_dump($time);
// echo $time;
?>
string(19) "2022-11-30 09:07:29"
时间戳
<?php
$time=time();//年-月-日 小时:分:秒
var_dump($time);
// echo $time;
?>
int(1669813684)
从1970-1-1 0:0:0开始(即此刻为0),每过一秒该函数返回值加1
基本概念
前端代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="index.php" enctype="multipart/form-data" method="post">
<input type="file" name="pict">
<br>
<input type="submit" value="上传">
</form>
</body>
</html>
后端代码
简单上传
<?php
if(move_uploaded_file($_FILES['pict']['tmp_name'],'receive/'.$_FILES['pict']['name']))
{
echo "文件上传成功";
}
else
{
echo "文件上传失败";
}
?>
防覆盖上传
<?php
$ext=pathinfo($_FILES['pict']['name'],PATHINFO_EXTENSION);
$randname=date('ymdhis').random_int(10000,99999);
$newfilename=$randname.'.'.$ext;
if(move_uploaded_file($_FILES['pict']['tmp_name'],'receive/'.$newfilename))
{
echo "文件上传成功";
}
else
{
echo "文件上传失败";
}
?>