我想用 php(文本文件)上传文件,并且总是将此文件保存为 names.txt(如果文件存在于以前的上传中,我想用新的文件替换)到脚本所在的同一目录。我从教程中在线找到了以下代码,但我无法使其工作。我没有文件存在。我已经发布了上传的 html 文件和 php 文件来帮助我。谢谢uploadfile.html
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="file_uploader.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
文件上传器.php
<?php
if( $_FILES['file']['name'] != "" )
{
copy( $_FILES['file']['name'], "/uploads" ) or
die( "Could not copy file!");
}
else
{
die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>
<h2>Uploaded File Info:</h2>
<ul>
<li>Sent file: <?php echo $_FILES['file']['name']; ?>
<li>File size: <?php echo $_FILES['file']['size']; ?> bytes
<li>File type: <?php echo $_FILES['file']['type']; ?>
</ul>
</body>
</html>