问题描述
我正在尝试使用服务器上的PHP脚本作为上传处理程序来上传文件。像这样的传统网络表单可以很好地工作:
<form action="uploadHandler.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
但是,当我尝试切换到拖放形式时,PHP处理程序失败,名称值“ fileToUpload”上的索引未定义。这是错误消息:
PHP Notice: Undefined index: fileToUpload in /home/...../uploadHandler.php on line 10
uploadHandler.php的第10行包含以下语句:
$fileName = $_FILES['fileToUpload']['name'];
我仍在以拖放形式使用name = fileToUpload:
<form class="my-form">
<p>Upload multiple files with the file dialog or by dragging and dropping images onto the dashed region</p>
<input type="file" id="fileToUpload" name="fileToUpload" onchange="handleFiles(this.files)">
<label class="button" for="fileElem">Select some files</label>
</form>
这是页面上的函数,其中包含调用uploadHandler的拖放形式:
function uploadFile(file,i) {
var url = 'https://xxxxxx/uploadHandler.php'
var xhr = new XMLHttpRequest()
var formData = new FormData()
xhr.open('POST',url,true)
xhr.setRequestHeader('X-Requested-With','XMLHttpRequest')
formData.append('file',file)
xhr.send(formData)
}
我在致电xhr.send之前尝试添加类似formData.append('name','fileToUpload')
的内容,但这似乎无济于事。
我想念什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)