Web で検索したところ、jQuery と iframe を使用した多くのソリューションが見つかりました。
jQuery、iframe、またはフラッシュなしでIE7/8用のAJAXファイルアップローダーを作成する方法を誰かに解決策を教えてもらえますか?
これは私のHTMLスクリプトです
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>Ajax Uploader</title>
<script>
function iajax()
{
oField=document.myform.myfile;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('eds').innerHTML=xmlhttp.responseText;
}
};
xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");
xmlhttp.open("post","file.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<form name='myform' enctype="multipart/form-data" method="post" onsubmit="iajax(this)">
<input type="file" name="myfile" />
<button type="submit">Upload file to the server</button>
</form>
<div id='eds'></div>
</body>
</html>
私のPHPスクリプト:
<?php
$name=$_FILES['myfile']['name'];
$type=$_FILES['myfile']['type'];
$size=$_FILES['myfile']['size'];
$temp_name=$_FILES['myfile']['tmp_name'];
if(!move_uploaded_file($_FILES['myfile']['tmp_name'], './public/'.$name))
{
echo "Image Uploading Error";
}
else
{
echo "Upload Image Name : ".$name;
}
?>