)
*/
date_default_timezone_set('asia/shanghai');
function upload_file($filename)
{
if($_FILES[$filename]['error'] > 0)
{
switch($_FILES[$filename]['error'])
{
case 1:
echo "上传附件不合法,超出php.ini的设置大小";
break;
case 2:
echo "上传附件不合法,超出max_file_size的设置大小";
break;
case 3:
echo "只上传了部分文件";
break;
case 4:
echo "没有上传文件";
break;
}
}else{
//进行附件具体上传
//1.附件大小判断
$uplode_size = 300000; //附件大小限制在300000k
if($uplode_size
{
echo "文件大小受限制(300000k以内)";
}else{
//2.附件类型判断
//pathinfo 返回文件的路径信息
$file_info = pathinfo($_FILES[$filename]['name']);
//上传附件类型的限制
//in_array //检查数组中存在某个值
$file_type = array('jpg','gif','png');
if(!in_array($file_info['extension'],$file_type))
{
echo "文件类型不符合";
}else{
$dir = "./uplode/";
$time_name = date('Ymd-His-').mt_rand(10000,99999);
$file_ext = $file_info['extension'];
$file_name = $dir.$time_name.".".$file_ext;
//move_uploaded_file(附件临时路径名,附件上传后的路径名)附件上传
if(move_uploaded_file($_FILES[filename]['tmp_name'],$file_name))
{
echo "文件上传成功";
}else
{
echo "文件上传失败";
}
}
}
}
}
upload_file('filename');
?>