目录
PHP文件上传前台编码:
PHP文件上传后台编码:
PHP文件上传前台编码:
代码语言:javascript复制<!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">
<p>
<input type="file" name="file" required>
</p>
<p>
<input type="submit" value="上传文件">
</p>
</form>
</body>
</html>
PHP文件上传后台编码:
代码语言:javascript复制<?php
$file=$_FILES["file"];
#随机文件名 文件的后缀名
$newFileName=uniqid().".".pathinfo($file['name'], PATHINFO_EXTENSION);
#move_uploaded_file(存储的缓存文件,存储路径/文件名称)
$result=move_uploaded_file($file['tmp_name'],$newFileName);
if($result){echo "上传成功";}else{echo"上传失败";}
?>
测试:
测试成功。