Initial commit
This commit is contained in:
46
20250103/upload_1.php
Normal file
46
20250103/upload_1.php
Normal file
@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>文件上传</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
// 定义文件上传目录
|
||||
$uploadDir = __DIR__ . "/upload/tmp/";
|
||||
|
||||
// 检查并创建目录
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
|
||||
// 处理文件上传
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["upload_file"])) {
|
||||
$file = $_FILES["upload_file"];
|
||||
$fileName = basename($file["name"]);
|
||||
$targetFile = $uploadDir . $fileName;
|
||||
|
||||
// 检查文件是否上传成功
|
||||
if ($file["error"] === UPLOAD_ERR_OK) {
|
||||
// 移动文件到指定目录
|
||||
if (move_uploaded_file($file["tmp_name"], $targetFile)) {
|
||||
echo "<p>文件上传成功!文件名:{$fileName}</p>";
|
||||
echo "<p>存储路径:{$targetFile}</p>";
|
||||
} else {
|
||||
echo "<p>文件上传失败,请检查目录权限!</p>";
|
||||
}
|
||||
} else {
|
||||
echo "<p>文件上传出错,错误码:" . $file["error"] . "</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- 文件上传表单 -->
|
||||
<form action="upload_1.php" method="post" enctype="multipart/form-data">
|
||||
<label for="upload_file">请选择文件:</label>
|
||||
<input type="file" id="upload_file" name="upload_file">
|
||||
<br><br>
|
||||
<input type="submit" id="ok" name="ok" value="上传">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user