嗨,我对 Web 开发很陌生,但有编码背景。我正在尝试为我正在创建的表单创建一个非常简单的多文件上传器,但是我一生都无法让它工作。我遵循了我在网上找到的教程,这是我到目前为止所拥有的。我得到了嗯回声哈
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="filesToUpload[]" id="filesToUpload" type="file" multiple="" onChange="makeFileList();" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</form>
<p>
<strong>Files You Selected:</strong>
</p>
<ul id="fileList"><li>No Files Selected</li></ul>
<script type="text/javascript">
function makeFileList() {
var input = document.getElementById("filesToUpload");
var ul = document.getElementById("fileList");
while (ul.hasChildNodes()) {
ul.removeChild(ul.firstChild);
}
for (var i = 0; i < input.files.length; i++) {
var li = document.createElement("li");
li.innerHTML = input.files[i].name;
ul.appendChild(li);
}
if(!ul.hasChildNodes()) {
var li = document.createElement("li");
li.innerHTML = 'No Files Selected';
ul.appendChild(li);
}
}
</script>
</body>
</html>
PHP
<?PHP
if(count($_FILES['uploads']['filesToUpload'])) {
foreach ($_FILES['uploads']['filesToUpload'] as $file) {
move_uploaded_file($file, "uploads/" . "sample.png" );
}
}else{
echo "hmm";
}
?>
编辑
好的,我将 php 文件更新为此,最初有一个回显,其中正确回显了我的文件但是我无法进行实际上传,现在我只想将文件添加到我已经设置权限的上传目录使用 filezilla 为 777 并希望保持文件的相同名称
<?PHP
if(count($_FILES['filesToUpload']['name'])) {
foreach ($_FILES['filesToUpload']['name'] as $file) {
move_uploaded_file($file, "uploads/" . $file );
}
}else{
}
?>
非常感谢您迄今为止的帮助!