刚写的一个文件上传类。欢迎评点
<br><br><br><title>上载文件表单</title><br><br>
登录后复制
define(UPLOAD_DIR,'D:\\AppServ\\www\\test\\upload\\');
define(UPLOAD_WEB_DIR,'\\test\\upload\\');
class upload_file_class{
var $input_name; //上传file的name
var $max_size; //最大上传大小 单位kb
var $allow_ext; //所允许的扩展名
var $err_info; //错误信息
/**
* 构造函数
*
* @param $input_name
* @param $max_size
* @param $allow_ext
* @return
*/
function __construct($input_name,$max_size=1024,$allow_ext=array('jpg','png','gif')){
$this->input_name = $input_name;
$this->max_size = $max_size;
$this->allow_ext = $allow_ext;
$this->err_info_arr = array(
1=>'上传文件大小超过了ini的设定值',
2=>'上传文件大小超过了表单设定的最大值',
3=>'文件只有部分被上传',
4=>'没有文件被上传',
5=>'上传文件大小超过了允许的设定值',
6=>'不是允许的上传文件类型',
7=>'创建目录失败,请确认是否有创建目录的权限',
8=>'创建文件失败,请重试。',
9=>'文件上传时产生错误,请重试。'
);
}
/**
*文件上传
*
* @return $file_path_arr 上传成功的文件路径数组
*/
public function upload(){
global $_FILES;
if( !is_array($this->input_name) )$this->input_name = array($this->input_name);
$file_path_arr = array();
foreach ($this->input_name as $k => $input_name ) {
$__F = $_FILES[$input_name];
if( !empty($__F) ){
if( $__F['error'] > 0 ){
//客户端上传产生错误
$this->set_err($__F['error']);
}
else{
$__F['size'] = $__F['size']/1024;
if( $this->max_size >= $__F['size'] ){
if( $this->check_ext($__F['name']) ){
$save_dir_info = $this->check_dir();
if( $save_dir_info ){
$rand_num = date('Ymdhis').rand(0,10000000);
$ext = $this->get_img_ext($__F['name']);
$new_file_name = $rand_num.".{$ext}";
$full_path = $save_dir_info['full_dir'].$new_file_name;
$full_web_path = $save_dir_info['full_web_dir'].$new_file_name;
if( !file_exists($full_path) ){
if( move_uploaded_file($__F['tmp_name'],$full_path) ){