问题
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?
回答1:
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>
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";
}
That will get you started =)
回答2:
User this http://jquery.malsup.com/form/#file-upload jquery plugin..Its best and tested..
来源:https://stackoverflow.com/questions/9514352/ie8-async-file-upload