Jquery AJAX图片上传

首先下载ajaxfileupload.js

//html


//jquery

//php页
if ((($_FILES["pic"]["type"] == "image/gif")|| ($_FILES["pic"]["type"] == "image/jpeg")|| ($_FILES["pic"]["type"] == "image/jpg")|| ($_FILES["pic"]["type"] == "image/png")|| ($_FILES["pic"]["type"] == "image/bmp")|| ($_FILES["pic"]["type"] == "image/pjpeg"))&& ($_FILES["pic"]["size"] < 10000000)){//100KB
$extend = explode(".",$_FILES["pic"]["name"]);
$key = count($extend)-1;
$ext = ".".$extend[$key];
$newfile = time().$ext;
$dirname=date('Ymd',time());
if(!file_exists('../uploadfile/'.$dirname)){mkdir('../uploadfile/'.$dirname);}
move_uploaded_file($_FILES["pic"]["tmp_name"],"../uploadfile/".$dirname."/" . $newfile);
@unlink($_FILES['pic']);
$pics="../uploadfile/".$dirname."/" . $newfile;
echo $pics;
}else {
echo 'error';
}
?>

你可能感兴趣的:(Jquery AJAX图片上传)