php文件上传之单文件上传,为了简单一些,php文件跟form表单写在了一个文件里.
php单文件上传---->
1 2 3 4 5 6 7 8 请选择要上传的文件:
9 10 11 12 13 14 15 16 17 0){24 switch($fileinfo['error']){25 case 1:26 $msg_error='上传文件超过了php配置文件中upload_max_filesize选项的值';27 break;28 case 2:29 $msg_error='超过了表单max_file_size限制的大小';30 break;31 case 3:32 $msg_error='文件部分上传';33 break;34 case 4:35 $msg_error='没有文件上传';36 break;37 case 6:38 $msg_error='没有找到临时目录';39 break;40 case 7:41 case 8:42 $msg_error='系统错误';43 break;44 }45 exit($msg_error);46 }47 $filename=$fileinfo['name'];48 //获取文件的扩展名49 $ext=strtolower(substr($filename,strrpos($filename,'.')+1));50 //定义可允许上传的扩展名51 $allowext=array('txt','html','png','gif','jpeg');52 //检测上传文件的类型53 if(!in_array($ext,$allowext)){54 exit('上传文件类型错误');55 }56 57 58 //检测文件的大小59 $maxsize=2097152;60 if($fileinfo['size']>$maxsize){61 exit('上传文件过大');62 }63 64 //检测是否为http post方式上传上来的65 if(!is_uploaded_file($fileinfo['tmp_name'])){66 exit('文件不是通过http post方式提交上来的');67 }68 69 //确保文件名字唯一,防止同名文件被覆盖70 $uniqname=md5(uniqid(microtime(true),true)).'.'.$ext;71 72 //定义保存在哪个文件夹下,如果没有该文件夹则创建73 $path='uploads';74 if(!file_exists($path)){75 mkdir($path,0777,true);76 chmod($path,0777);77 }78 $destination=$path.'/'.$uniqname;79 80 //移动文件至要保存的目录81 if(! @move_uploaded_file($fileinfo['tmp_name'],$destination)){82 exit('文件上传失败');83 }84 85 echo '上传成功';86 87 }88 ?>
http://www.bkjia.com/phpjc/1036616.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1036616.htmltecharticlephp文件上传之单文件上传, 为了简单一些,php文件跟form表单写在了一个文件里. php单文件上传---- 1 !doctype html 2 html 3 head 4 meta charset=utf-8...