Ajax Upload文件上传插件上传图片php实例
JavaScript部分代码:
window.onload = function(){
var oBtn = document.getElementById("unloadPic");
var oShow = document.getElementById("uploadedName");
var oRemind = document.getElementById("errorRemind");
new AjaxUpload(oBtn,{
action:"file_upload.php",
name:"upload",
onSubmit:function(file,ext){
if(ext && /^(jpg|jpeg|png|gif)$/.test(ext)){
//ext是后缀名
oBtn.value = "正在上传…";
oBtn.disabled = "disabled";
}else{
oRemind.style.color = "#ff3300";
oRemind.innerHTML = "不支持非图片格式!";
return false;
}
},
onComplete:function(file,response){
oBtn.disabled = "";
oBtn.value = "再上传一张图片";
oRemind.innerHTML = "";
var newChild = document.createElement("li");
newChild.innerHTML = file;
oShow.appendChild(newChild);
}
});
};
PHP部分代码:
$file_path = '../../../uploads/';
$file_up = $file_path.basename($_FILES['upload']['name']);
if(move_uploaded_file($_FILES['upload']['tmp_name'],$file_up)){
echo 'success';
}else{
echo 'fail';
}