我正在使用此代码一次上传多个文件,但它无法正常工作。它根本不会触发;
<form action="imgur.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="file[]" type="file" multiple="multiple" onchange="upload(this.files[0])" />
</form>
<?php
foreach ($_FILES['file']['tmp_name'] as $index => $tmpName) {
if( !empty( $tmpName ) && is_uploaded_file( $tmpName ) )
{
?>
<script type="text/javascript">
window.ondragover = function(e) {e.preventDefault()}
window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
function upload(file) {
if (!file || !file.type.match(/image.*/)) return;
document.body.className = "uploading";
var fd = new FormData();
fd.append("image", file);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.imgur.com/3/image.json");
xhr.onload = function() {
var code = JSON.parse(xhr.responseText).data.link + '\n';
var editor = eval('opener.' + 'clickableEditor');
editor.performInsert(code);
javascript:window.close()
}
xhr.setRequestHeader('Authorization', 'Client-ID [MY-CLIENT-ID]');
xhr.send(fd);
}
</script>
<?php
}
}
?>
此代码粘贴的文件名称为imgur.php
请帮忙!