一个实用的php 文件上传类代码
这里是来自网络朋友的一个实现的文件上传类代码,我们详细的介绍了每个变量的用处,下面看看吧,有需要可以参考一下,实例类代码如下:
- <?php
-
-
-
- class uploadFile {
-
- public $max_size = '1000000';
- public $file_name = 'date';
- public $allow_types;
- public $errmsg = '';
- public $uploaded = '';
- public $save_path;
- private $files;
- private $file_type = array();
- private $ext = '';
-
-
-
-
-
-
-
- public function __construct($save_path = './upload/',$file_name = 'date',$allow_types = '') {
- $this->file_name = $file_name;
- $this->save_path = (preg_match('//$/',$save_path)) ? $save_path : $save_path . '/';
- $this->allow_types = $allow_types == '' ? 'jpg|gif|png|zip|rar' : $allow_types;
- }
-
-
-
-
-
-
-
- public function upload_file($files) {
- $name = $files['name'];
- $type = $files['type'];
- $size = $files['size'];
- $tmp_name = $files['tmp_name'];
- $error = $files['error'];
-
- switch ($error) {
- case 0 : $this->errmsg = '';
- break;
- case 1 : $this->errmsg = '超过了php.ini中文件大小';
- break;
- case 2 : $this->errmsg = '超过了MAX_FILE_SIZE 选项指定的文件大小';
-