焦点图片上传到文件数据库,请怀疑在使用上的问题,AJAX
我有以下HTML
<form enctype="multipart/form-data" onsubmit="uploadProfilePicture();" method="post" name="prof_picture">
<input id="upload_profile_picture" style="display:none;"name="image" accept="image/jpeg" type="file">
<input id="upload_profile_picture2" value="Submit" type="submit" style="display:none;">
<a id="change_profile_picture" class="profile_option" onclick="$('#upload_profile_picture').click();">Mudar foto de perfil</a>
PHP(profileFunctions.php)
if(isset($_POST['prof_picture'])){
alert("test");
}
JS
function uploadProfilePicture(){
$.ajax({
type:'POST',
url: "profile/profileFunctions.php",
data:$(this).serialize(),
cache:false,
success:function(data){
console.log("success");
console.log(data);
},
error: function(data){
console.log("error");
console.log(data);
}
});
}
我已经使用AJAX之前,但事情是我其实真的很怀疑,因为这个文件的是图像:
1º究竟应该在“数据:”什么内ajax请求?我应该怎样做才能正确解析文件?
2º在PHP图像验证中,如何检索 文件的扩展名以及我应该如何执行isset($ _ POST)?
3º如果我要向用户即时提出图像,如果ajax.success 应将缓存设置为true?缓存如何处理这种情况?
你有没有考虑过使用像uploadify这样的插件? http://www.uploadify.com/ –
我不建议将图像数据放入数据库。我建议将其保存到文件系统并将其位置存储到数据库中。 –
@JustinWood我从来没有说过我会:) – user111671