Ejemplo n.º 1
0
 function swfsave_action(){
     if (is_array($_FILES['Filedata'])) {
         $upload = new upload();
         $upload->dir = 'images';
         $upload->max_size = 2048000;
         $attachment = new attachment();
         $_file_type = str_replace(',','|',config::get('upload_filetype'));
         $file = $_FILES['Filedata'];
         $file['name'] = strtolower($file['name']);
         if ($file['size'] > $upload->max_size) {
             echo "附件超过上限(".ceil($upload->max_size / 1024)."K)!');";
             exit;
         }
         if (!front::checkstr(file_get_contents($file['tmp_name']))) {
             echo '上传失败!请将图片保存为WEB格式!';
             exit;
         }
         if (!$file['name'] || !preg_match('/\.('.$_file_type.')$/',$file['name'])){
             echo '上传失败!不允许的文件类型!';
             exit;
         }
         $filename = $upload->run($file);
         if(config::get('watermark_open')) {
             include_once ROOT.'/lib/plugins/watermark.php';
             imageWaterMark($filename,config::get('watermark_pos'),config::get('watermark_path'),null,5,"#FF0000",config::get('watermark_ts'),config::get('watermark_qs'));
         }
         if (!$filename) {
             echo "附件保存失败!";
             exit;
         }
         echo 'ok_'.$filename;
         exit;
     }else{
         exit('请添加文件');
     }
 }
Ejemplo n.º 2
0
    function run($attachment) {
        $this->max_size=config::get('upload_max_filesize') * 1024000;
        if (!isset($this->url_pre))
            $this->url_pre='upload/'.$this->dir.'/'.date('Ym');
        $this->path=ROOT.'/'.$this->url_pre;
        tool::mkdir($this->path);
        if (!$attachment['name']) {

            return false;
        }
        $new_name=$new_name_gbk=str_replace('.','',Time::getMicrotime()).'.'.end(explode('.',$attachment['name']));
        $content=file_get_contents($attachment['tmp_name']);
        if (!front::checkstr($content)) {
            return false;
        }
        
        if (strlen($content) >$this->max_size) {
            return false;
        }
        
        if(!in_array(end(explode('.',$attachment['name'])), $this->type)){
            return false;
        }
        move_uploaded_file($attachment['tmp_name'],$this->path.'/'.$new_name_gbk);
        $this->save_path=$this->path.'/'.$new_name_gbk;
        if ($_GET['site'] != 'default') {
            $ftp=new nobftp();
            $ftpconfig=config::get('website');
            $ftp->connect($ftpconfig['ftpip'],$ftpconfig['ftpuser'],$ftpconfig['ftppwd'],$ftpconfig['ftpport']);
            $ftperror=$ftp->returnerror();
            if ($ftperror) {
                exit($ftperror);
            }
            else {
                $ftp->nobchdir($ftpconfig['ftppath']);
                $ftp->nobput($ftpconfig['ftppath'].'/'.$this->url_pre.'/'.$new_name,$this->save_path);
            }
        }
        return $this->url_pre.'/'.$new_name;
    }
Ejemplo n.º 3
0
    function uploadimage_action() {
        $res=array();
        $uploads=array();
        if (is_array($_FILES)) {
            $upload=new upload();
            $upload->dir='images';
            $upload->max_size=config::get('upload_max_filesize')*1024*1024;
            $attachment=new attachment();
            $_file_type=str_replace(',','|',config::get('upload_filetype'));
            foreach ($_FILES as $name=>$file) {
                $res[$name]['size']=ceil($file['size'] / 1024);
                if ($file['size'] >$upload->max_size) {
                    $res[$name]['code']="alert('附件超过上限(".ceil($upload->max_size / 1024)."K)!');";
                    break;
                }
                if (!front::checkstr(file_get_contents($file['tmp_name']))) {
                    $res[$name]['code']=lang('上传失败!附件没有通过验证!');
                    break;
                }
                if (!$file['name'] ||!preg_match('/\.('.$_file_type.')$/',$file['name']))
                    continue;
                $uploads[$name]=$upload->run($file);
                if (!$uploads[$name]) {
                    $res[$name]['code']="alert('".lang('附件保存失败!')."');";
                    break;
                }
                $res[$name]['name']=$uploads[$name];
                $res[$name]['type']=$file['type'];
                $rname=preg_replace('%(.*)[\\\\\/](.*)_\d+(\.[a-z]+)$%i','$2$3',$uploads[$name]);
                $res[$name]['code']="
                document.form1.attachment_id.value=data[key].id;
                if(!document.form1.attachment_intro.value) {
                document.form1.attachment_intro.value='$rname';
                }
                get('attachment_path').innerHTML=data[key].name;
                get('file_info').innerHTML='附件已保存!大小为:'+data[key].size+'K ';
                        ";
                if(substr(config::get('base_url'),-1,1) != '/'){
                	$ex = '/';
                }
                $str = config::get('base_url').$ex.$uploads[$name];
				echo $str;
                return;
            }
        }
        echo json::encode($res);
    }