IE8异步文件上传文件上传

2023-09-10 13:51:13 作者:枪打天下

我想找到例如code到(通过Ajax)asyncronously上传文件在IE8。同时上传进度将是很好的,但不是强制性的。标识如PHP code到能够处理的文件服务器端。我把整个示例使用FORMDATA其他浏览器来了,但我不能使用它。难道任何机构请点我在正确的方向?

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?

推荐答案

这是关于这个问题的一个很好的教程:的 http://hungred.com/how-to/tutorial-easiest-asynchronous-upload-file-ajax-upload/

This is a good tutorial on the subject: 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>

记者:

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";
}

这将让你开始=)