phpcms模块开发之swfupload的使用介绍(6)

$this->field = $field;
        $this->savepath = $this->upload_root.$this->upload_dir.date('Ymd');//这里我们需要修改下.也可以不修改.在我们实例化这个类的时候再来指定目录.
        $this->alowexts = $alowexts;
        $this->maxsize = $maxsize;
        $this->overwrite = $overwrite;
        $uploadfiles = array();
        $description = isset($GLOBALS[$field.'_description']) ? $GLOBALS[$field.'_description'] : array();
        if(is_array($_FILES[$field]['error'])) {
            $this->uploads = count($_FILES[$field]['error']);
            foreach($_FILES[$field]['error'] as $key => $error) {
                if($error === UPLOAD_ERR_NO_FILE) continue;
                if($error !== UPLOAD_ERR_OK) {
                    $this->error = $error;
                    return false;
                }
                $uploadfiles[$key] = array('tmp_name' => $_FILES[$field]['tmp_name'][$key], 'name' => $_FILES[$field]['name'][$key], 'type' => $_FILES[$field]['type'][$key], 'size' => $_FILES[$field]['size'][$key], 'error' => $_FILES[$field]['error'][$key], 'description'=>$description[$key],'fn'=>$fn);
            }
        } else {
            $this->uploads = 1;
            if(!$description) $description = '';
            $uploadfiles[0] = array('tmp_name' => $_FILES[$field]['tmp_name'], 'name' => $_FILES[$field]['name'], 'type' => $_FILES[$field]['type'], 'size' => $_FILES[$field]['size'], 'error' => $_FILES[$field]['error'], 'description'=>$description,'fn'=>$fn);
        }

if(!dir_create($this->savepath)) {
            $this->error = '8';
            return false;
        }
        if(!is_dir($this->savepath)) {
            $this->error = '8';
            return false;
        }
        @chmod($this->savepath, 0777);

if(!is_writeable($this->savepath)) {
            $this->error = '9';
            return false;
        }
        if(!$this->is_allow_upload()) {
            $this->error = '13';
            return false;
        }
        $aids = array();
        foreach($uploadfiles as $k=>$file) {
            $fileext = fileext($file['name']);
            if($file['error'] != 0) {
                $this->error = $file['error'];
                return false;
            }
            if(!preg_match("/^(".$this->alowexts.")$/", $fileext)) {
                $this->error = '10';
                return false;
            }
            if($this->maxsize && $file['size'] > $this->maxsize) {
                $this->error = '11';
                return false;
            }
            if(!$this->isuploadedfile($file['tmp_name'])) {
                $this->error = '12';
                return false;
            }
            //$temp_filename = $this->getname($fileext);//名称在这里.我们需要修改下
       $temp_filename = $file['tmp_name'].$fileext; //修改成原来的系统文件名称.
       $savefile = $this->savepath.$temp_filename; $savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile); $filepath = preg_replace(new_addslashes("|^".$this->upload_root."|"), "", $savefile); if(!$this->overwrite && file_exists($savefile)) continue; $upload_func = $this->upload_func; if(@$upload_func($file['tmp_name'], $savefile)) { $this->uploadeds++; @chmod($savefile, 0644); @unlink($file['tmp_name']); $file['name'] = iconv("utf-8",CHARSET,$file['name']); $uploadedfile = array('filename'=>$file['name'], 'filepath'=>$filepath, 'filesize'=>$file['size'], 'fileext'=>$fileext, 'fn'=>$file['fn']); $thumb_enable = is_array($thumb_setting) && ($thumb_setting[0] > 0 || $thumb_setting[1] > 0 ) ? 1 : 0; $image = new image($thumb_enable,$this->siteid); if($thumb_enable) { $image->thumb($savefile,'',$thumb_setting[0],$thumb_setting[1]); } if($watermark_enable) { $image->watermark($savefile, $savefile); } $aids[] = $this->add($uploadedfile); } } return $aids; }


注:这里我们可以再系统的attachment模块下建立MY_attachment.php  但是这样会影响系统的附件上传功能.

在我们自己的控制器里面.我们这个时候就需要加载自己写的类了.

复制代码 代码如下:


pc_base::load_app_class('你的模块名','',0);


其余的操作可以参照系统的attachment模块下的attachments控制器里面的swfupload方法来修改.

至此.我便完成了我的目的.在不改变系统文件目录的基础上.完成我自己想要的文件上传功能.

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/f3c06aaa98cc50e552f6533d7219ae47.html