对象是将两个文件发送到PHP服务器,看是否相同。
服务器是要发送消息,要么两个文件相同
或列出它们不同的第一行(计算新行字符)
与两个文件中该行的内容进行视觉比较。
首先是代码 - 在 JAVASCRIPT
var OFC
function CompFiles() {
OFC = document.getElementById('FC')
OFC.innerHTML = '<i>comparing files at a web site</i>'
FD = new FormData()
t = document.getElementsByName('file1')
t = t[0]
v = t.value
if (v == '') {
OFC.innerHTML = '<red>file 1 has not beed selected yet</red>'
t.focus()
return
}
FD.append('file1', t)
t = document.getElementsByName('file2')
t = t[0]
v = t.value
if (v == '') {
OFC.innerHTML = '<red>file 2 has not beed selected yet</red>'
t.focus()
return
}
FD.append('file2', t)
RQ = new XMLHttpRequest()
RQ.open("Post", 'comp03.php')
RQ.onload = (progress) => {
CheckSt(RQ)
}
RQ.open("Post", 'comp03.php')
RQ.send(FD)
}
function CheckSt(RD) {
O = OFC
if (RD.status == 200) O.innerHTML = '<blue>' + RD.responseText + '</blue>'
else O.innerHTML = '<red>Problem XMLHttpResponse = ' + RD.status == 200 + '</red>'
}
然后在< body >
<p>See if two files are equal. See first line where they differ<br>
First file: <input type='file' name='file1'> Second file: <input type='file' name='file2'>
<button onclick='CompFiles()'>compare the two files</button><br>
<span id='FC'> </span></p>
文件未在 PHP 中显示,count($_FILES) 为零。 count($_POST) 也是零。 我究竟做错了什么?我怀疑 FD.append 有问题,但是什么?