javascript IE8 异步文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9514352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE8 Async file upload
提问by craig1231
I am trying to find example code to upload files asyncronously (via Ajax) in IE8. Also upload progress would be nice, but not mandatory. Id like PHP code to be able to deal with the file server side. I keep coming across examples for other browsers using FormData, but I cannot use that. Could any body please point me in the right direction?
我试图找到示例代码以在 IE8 中异步上传文件(通过 Ajax)。上传进度也会很好,但不是强制性的。我喜欢 PHP 代码能够处理文件服务器端。我不断遇到使用 FormData 的其他浏览器的示例,但我无法使用它。任何机构都可以指出我正确的方向吗?
回答by Niklas
This is a good tutorial on the subject: http://hungred.com/how-to/tutorial-easiest-asynchronous-upload-file-ajax-upload/
这是关于该主题的一个很好的教程:http: //hungred.com/how-to/tutorial-easiest-asynchronous-upload-file-ajax-upload/
HTML:
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:
JS:
function redirect()
{
//'my_iframe' is the name of the iframe
document.getElementById('my_form').target = 'my_iframe';
document.getElementById('my_form').submit();
}
PHP:
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";
}
That will get you started =)
这会让你开始=)
回答by Rajesh
User this http://jquery.malsup.com/form/#file-uploadjquery plugin..Its best and tested..
使用这个http://jquery.malsup.com/form/#file-uploadjquery 插件..它是最好的并经过测试..