<?php
if(count($_FILES) > 0)
{
echo('<pre>');
var_dump($_FILES);
die('</pre>');
}
?>
<html>
<head>
<title>Simple file upload with iframe</title>
</head>
<body>
<form enctype='multipart/form-data' method='post' action='<?php echo($_SERVER['PHP_SELF']); ?>' target='iframe'>
<input name='file' type='file' />
<input type='submit' value='Send' />
</form>
<iframe name='iframe' style='width: 800px; height: 400px;'></iframe>
</body>
</html>
據我知道你不能上傳與AJAX文件,僅僅是因爲你無法訪問文件。瀏覽器保護了輸入類型=文件的內容,例如,IE7將提供C:\ fakepath \ filename.ext,而Firefox只會提供filename.ext。但是這些是字符串,而不是文件本身。所以你真的需要使用表單提交來提交文件。上述
的代碼將發佈表單內容的iframe,這是你有問題,一個常用的解決方法,防止頁面重新加載從。