当我上传图片时,服务器返回"清空"。
我需要从服务器或客户端更改为什么? 我只想上传一张图片而且我没有表格等 HTML:
输入id =" imgupload"类型="文件"值="上传"
客户端:
var reader = new FileReader();
function readURL(input) {
var fileTypes = ['jpg', 'jpeg', 'png'];
var extension = input.files[0].name.split('.').pop().toLowerCase(),
isSuccess = fileTypes.indexOf(extension) > -1;
if (isSuccess) {
reader.onload = function (e)
{
$('#img').attr('src', e.target.result);
$('#imguploadinput').hide();
$('#imguploadmenu').show();
$( "#imgsave" ).click(function() {
imagesave(e.target.result);
});
}
reader.readAsDataURL(input.files[0]);
}
else{
imagedelete();
$('#error').html("file error!");
}
}
function imagesave(img){
//$('#imguploadmenu').hide();
$.ajax({
url: "system/profile/uploadimage.php",
type: "POST",
data: {img:img},
success: function (data) {
$("#imgSpinner1").hide();
$('#error').html(data);
},
beforeSend: function() {
$("#imgSpinner1").show();
}
});
}
服务器端:
$imageInfo = getimagesize($_FILES['img']['tmp_name']);
if ($imageInfo['mime'] == ("image/png") || $imageInfo['mime'] == ("image/jpeg")
|| $imageInfo['mime'] == ("image/gif") ||
$imageInfo['mime'] == ("image/bmp")) {
echo "ok";
}
else
{
if(empty($_FILES['img'])) echo "empty";
else echo "no empty";
}