我正试图找到在 IE8 中异步上传文件(通过 Ajax)的示例代码。上传进度也很好,但不是强制性的。我喜欢 PHP 代码能够处理文件服务器端。我不断遇到其他浏览器使用 FormData 的示例,但我不能使用它。任何人都可以指出我正确的方向吗?
最佳答案
这是关于该主题的一个很好的教程:http://hungred.com/how-to/tutorial-easiest-asynchronous-upload-file-ajax-upload/
HTML:
<form id="my_form" name="form" action="upload.php" method="POST"
enctype="multipart/form-data" >
<div id="main">
<input name="my_files" id="my_file" size="27" type="file" />
<input type="button" name="action" value="Upload" onclick="redirect()"/>
<iframe id='my_iframe' name='my_iframe' src="">
</iframe>
</div>
</form>
JS:
function redirect()
{
//'my_iframe' is the name of the iframe
document.getElementById('my_form').target = 'my_iframe';
document.getElementById('my_form').submit();
}
PHP:
$uploaddir = '/images/';
$uploadfile = $uploaddir . basename($_FILES['my_files']['name']);
if (move_uploaded_file($_FILES['my_files']['my_name'], $uploadfile)) {
echo "success";
} else {
echo "error";
}
这会让你开始 =)
关于php - IE8 异步文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9514352/