首页 > 代码库 > php上传图片

php上传图片


$_files= array("image/jpg","image/jpeg","image/png","image/pjpeg","image/gif","image/bmp","image/x-png");
if(is_array($_files))
{
if(!in_array($_FILES[‘userfile‘][‘type‘],$_files))
{
echo "<script>alert(‘图片类型不符合,请重新上传‘);history.back();</script>";
exit;
}

}
if($_FILES[‘userfile‘][‘error‘]>0){
switch($_FILES[‘userfile‘][‘error‘]){
case 1:_alert_back("上传文件超约定的值");
break;
case 2:_alert_back("上传文件超约定的值");
break;
case 3:_alert_back("部分文件上传");
break;
case 4:_alert_back("没有文件上传");
break;
}
exit;

}
//判断配置大小
if($_FILES[‘userfile‘][‘size‘]>2097152){
_alert_back("超过10000");
}
if(is_uploaded_file($_FILES[‘userfile‘][‘tmp_name‘]))
{
if(!@move_uploaded_file($_FILES[‘userfile‘][‘tmp_name‘],‘photo\1492310565\\‘.$_FILES[‘userfile‘][‘name‘]))
{
_alert_back("移动失败");
}
else{
_alert_back("上传文件成功");
}

}else{
_alert_back("上传文件不存在");
}

php上传图片