0
carica.html上传图片用PHP通过JavaScript
<td>
<input type="file" size="30" onchange="preview()" id="upload_immagine">
</td>
<td>
<div id="divImmagine" > </div>
</td>
filejavascript.js
function preview()
{
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("divImmagine").innerHTML=xmlhttp.responseText;
}
image=request.getParameter("upload_immagine");
document.getElementById("divImmagine").innerHTML=image;
xmlhttp.open("POST","stampaAnteprima.php", false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("image="+image);
}
stampaAnteprima.php
<?php
$file_temp=($_FILES['image']['tmp_name']);
echo"$file_temp";
?>
的JavaScript线image=request.getParameter("upload_immagine");
没有返回。我怎么得到的价值传递给PHP,然后通过$_FILES['image']['tmp_name']
在实践中读取文件,这将是形象?你有什么建议吗?
标准ajax不允许上传文件。 – 2014-10-27 17:06:04
使用malsups文件上传插件jquery链接:http://malsup.com/jquery/form/ – 2014-10-27 17:16:38
另一个好的解决方案是:http://fineuploader.com/ – briansol 2014-10-27 17:19:31