【问题标题】:IE8 Async file uploadIE8 异步文件上传
【发布时间】:2012-03-01 10:15:56
【问题描述】:

我正在尝试在 IE8 中查找示例代码以异步(通过 Ajax)上传文件。上传进度也会很好,但不是强制性的。我希望 PHP 代码能够处理文件服务器端。我不断遇到使用 FormData 的其他浏览器的示例,但我不能使用它。任何人都可以指出我正确的方向吗?

【问题讨论】:

  • 看起来不错的教程:hungred.com/how-to/…
  • 唯一的选择是通过iframe提交表单
  • 所以不可能通过 Ajax 实现??
  • 这将在后台像 Ajax 一样工作。但是使用 ajax 是不可能的(至少在 ie8 中)
  • @Niklas 你想把它作为答案吗......考虑到我决定使用它,我会接受它作为答案。

标签: php javascript ajax internet-explorer-8


【解决方案1】:

这是一个很好的教程: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";
}

这会让你开始 =)

【讨论】:

    【解决方案2】:

    使用这个http://jquery.malsup.com/form/#file-upload jquery 插件..它是最好的和经过测试的..

    【讨论】:

    • 我用过。它在 IE 中工作正常,除了 uploadProgress 在 IE 中不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多