Php 未通过ajax上传图像
我正试图通过提交表单上传图像。以下是我的代码片段: html:Php 未通过ajax上传图像,php,ajax,image,Php,Ajax,Image,我正试图通过提交表单上传图像。以下是我的代码片段: html: <form method="POST" id="statusform" action="insertstatus.php" enctype="multipart/form-data"> <textarea name="statusText" onclick="javascript:this.value='';" class="retroText" style="width:600px;height:100px;fo
<form method="POST" id="statusform" action="insertstatus.php" enctype="multipart/form-data">
<textarea name="statusText" onclick="javascript:this.value='';" class="retroText" style="width:600px;height:100px;font-family:lucida sans unicode,lucida grande,sans-serif;resize:none;padding:5px;">Post your crap here ...</textarea>
<input type="file" name="statusPhoto" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png" size="26" />
</form>
$("#statusform").submit(function() {
$.post($("#statusform").attr("action"), $("#statusform").serialize(), function(data){
alert(data);
});
//Important. Stop the normal POST
return false;
});
if(isset($_FILES['statusPhoto']) && $_FILES['statusPhoto']['size'] > 0)
{
<Image Upload Code>
}
else
echo "Photo not submitted";
php:
<form method="POST" id="statusform" action="insertstatus.php" enctype="multipart/form-data">
<textarea name="statusText" onclick="javascript:this.value='';" class="retroText" style="width:600px;height:100px;font-family:lucida sans unicode,lucida grande,sans-serif;resize:none;padding:5px;">Post your crap here ...</textarea>
<input type="file" name="statusPhoto" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png" size="26" />
</form>
$("#statusform").submit(function() {
$.post($("#statusform").attr("action"), $("#statusform").serialize(), function(data){
alert(data);
});
//Important. Stop the normal POST
return false;
});
if(isset($_FILES['statusPhoto']) && $_FILES['statusPhoto']['size'] > 0)
{
<Image Upload Code>
}
else
echo "Photo not submitted";
if(isset($\u文件['statusPhoto'])&&&$\u文件['statusPhoto']['size']>0)
{
}
其他的
回显“照片未提交”;
从ajax返回的消息是:照片未提交。
请帮忙 您正在上载,而不是图像,您正在上载它的名称
$(“#statusform”).serialize()
返回一个字符串,图像是一个blob。尝试使用一些,例如。您可以通过iframe异步上传文件,如本文所述:
我只是在测试是否设置了$\u文件['statusPhoto']。。但事情本身就失败了……好吧。我明白。但是,如果我不想使用这个插件,可能的解决方案是什么<代码>$\u您的
$文件将始终为空。post
,因为您不发送文件内容,只发送文件名。如果您不想重新加载页面,请尝试将表单提交到iframe。您必须使用FormData对象使用ajax上载文件