pc ms 모듈 개발 swfupload 사용 안내

25497 단어 phpcms 모듈swfupload
pc ms 모듈 을 본 격 적 으로 접 한 후 몇 가지 기능 모듈 을 개 발 했 습 니 다.그 중에서 사진 을 대량으로 업로드 해 야 하 는 문제 가 발생 하여 pc ms 에 있 는 swfupload 의 용법 을 발굴 하기 시 작 했 습 니 다.
phpcms 에 있 는 콘 텐 츠 형식 에서 그림 그룹 을 직접 지정 할 수 있 습 니 다.그러나 이러한 그림 그룹 기능 은 제 가 사용 하고 싶 은 것 이 아 닙 니 다.정적 html 파일 전 체 를 업로드 해 야 합 니 다.필요 합 니 다.
폴 더 전 체 를 업로드 하 는 방법 을 찾 을 수 있 습 니 다.또한 원래 파일 이름 을 유지 할 수 있 습 니 다.
목적 총 결 은 다음 과 같다.
1.시스템 의 파일 과 디 렉 터 리 구 조 를 바 꾸 지 않 습 니 다.
2,다 중 첨부 파일 업로드 기능 을 실현 합 니 다.
3,업 로드 된 폴 더 이름 을 얻 을 수 있 습 니 다.
phpcms 에 첨부 파일 업로드 기능 이 있 습 니 다.swfupload 기능 을 사용 하고 싶 습 니 다.이 기능 은 phpcms 의 첨부 파일 업로드 기능 에 통합 되 었 습 니 다.제 가 하려 는 것 은 추출 하고 수정 하 는 것 입 니 다.
첫 번 째 단 계 는 이것 이 어떻게 호출 되 었 는 지 연구 하 겠 습 니 다.
우선 fireforx 브 라 우 저의 firebug 를 엽 니 다.   네트워크 패 널 을 엽 니 다.phopcm 에서 swfupload 를 찾 았 습 니 다.호출 된 단 추 를 찾 았 습 니 다.시스템 이 요청 한 연결 이 무엇 인지 보 세 요.

?m=attachment&c=attachments&a=swfupload&args=10,,1&module=&catid=&authkey=b756a93dea2e627293e88fa9d62af709&pc_hash=iXFbo1
우 리 는 이러한 요청 을 포착 하 였 습 니 다.attachment 모듈 의 attachements 컨트롤 러 안의 swfupload 방법 을 호출 하 였 습 니 다.
우 리 는 이 모듈 의 이 컨트롤 러 안의 이 방법 을 찾 아 냈 다.
phpcms/modoules/attachemet/attachemts.php 에 있 습 니 다.
열 어 보 세 요.코드 는 다음 과 같 습 니 다

public function swfupload(){
        $grouplist = getcache('grouplist','member');
        if(isset($_POST['dosubmit'])){
      //if . . swfupload .
        } else {
            if($this->isadmin==0 && !$grouplist[$this->groupid]['allowattachment']) showmessage(L('att_no_permission'));
            $args = $_GET['args'];//
            $authkey = $_GET['authkey'];//
            if(upload_key($args) != $authkey) showmessage(L('attachment_parameter_error'));//
            extract(getswfinit($_GET['args']));//
            $siteid = $this->get_siteid();// id
            $site_setting = get_site_setting($siteid);//
            $file_size_limit = sizecount($site_setting['upload_maxsize']*1024);//
            $att_not_used = param::get_cookie('att_json');//
            if(empty($att_not_used) || !isset($att_not_used)) $tab_status = ' class="on"';// on
            if(!empty($att_not_used)) $div_status = ' hidden';//            
            $att = $this->att_not_used();//
            include $this->admin_tpl('swfupload');// . .
        }
    }
앞 에 있 는 저 희 는 상관 하지 않 습 니 다.그것 은 올 린 것 을 처리 하 는 것 입 니 다.저 는 else 부터 보 겠 습 니 다.먼저 첨부 파일 업로드 허용 여 부 를 검 증 했 습 니 다.
그리고$GET 에 서 는 swfupload 의 인자 args 를 얻 은 후 밀 스푼 을 검 증 했 습 니 다.밀 스푼 은 args 를 분석 하 는 것 을 통 해 사이트 의 id 를 얻 고 사이트 의 설정 을 받 아 첨부 파일 을 업로드 할 수 있 는 크기 를 얻 었 습 니 다.쿠키 에서 사용 되 지 않 은 첨부 파일 목록 을 얻 었 습 니 다.
템 플 릿 에 있 는 여러 가지 디 스 플레이 를 설정 합 니 다.마지막 으로 가장 중요 한 것 입 니 다.swfupload 템 플 릿 을 사 용 했 습 니 다.즉,이 템 플 릿 을 찾 아야 합 니 다.swfupload 가 어떻게 가 져 왔 는 지 보 세 요.
템 플 릿 여기 있 습 니 다:phpcms/modules/attachment/templates/swfupload.tpl.php
템 플 릿 파일 을 엽 니 다.템 플 릿 파일 에 파일 이 들 어 왔 습 니 다.

<?php $show_header = $show_validator = $show_scroll = 1; include $this->admin_tpl('header', 'attachment');?>
<link href="<?php echo JS_PATH?>swfupload/swfupload.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/swfupload.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/fileprogress.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/handlers2.js"></script>
<script type="text/javascript">
<?php echo initupload($_GET['module'],$_GET['catid'],$args,$this->userid,$this->groupid,$this->isadmin)?>
</script>
먼저 헤더 파일 을 도 입 했 습 니 다.대충 안 을 들 여 다 보 겠 습 니 다.안에 jquery 같은 것 이 있 습 니 다.필요 한 파일 입 니 다.그래서 잠시 후에 우리 가 사용 할 때 도 이 머리 를 도입 해 야 합 니 다.
다음은 swfupload 의 스타일 파일 과 필요 한 JS 입 니 다.시스템 함수 initupload 를 호출 했 습 니 다.이 함 수 는 도대체 무엇 입 니까?
절대 이 줄 을 얕 보지 마 세 요.swfupload 의 모든 설정 이 여기에 있 습 니 다.
우리 이 함 수 를 찾 아 보 자.
phpcms/modules/attachment/functions/golable.func.php 에서 그 흔적 을 찾 았 습 니 다.코드 는 다음 과 같 습 니 다.이 함수 의 주요 역할 은 swfupload 이 플러그 인 을 설정 하 는 것 입 니 다.

/* flash
     * swfupload
     * @param $module
     * @param $catid id
     * @param $args
     * @param $userid id
     * @param $groupid id
     * @param $isadmin
     */
    function initupload($module, $catid,$args, $userid, $groupid = '8', $isadmin = '0'){
        $grouplist = getcache('grouplist','member');
        if($isadmin==0 && !$grouplist[$groupid]['allowattachment']) return false;
        extract(getswfinit($args));
        $siteid = param::get_cookie('siteid');
        $site_setting = get_site_setting($siteid);
        $file_size_limit = $site_setting['upload_maxsize'];
        $sess_id = SYS_TIME;
        $swf_auth_key = md5(pc_base::load_config('system','auth_key').$sess_id);
        $init =  'var swfu = \'\';
        $(document).ready(function(){
        swfu = new SWFUpload({
            flash_url:"'.JS_PATH.'swfupload/swfupload.swf?"+Math.random(),
            upload_url:"'.APP_PATH.'index.php?m=attachment&c=attachments&a=swfupload&dosubmit=1",
            file_post_name : "Filedata",
            post_params:{"SWFUPLOADSESSID":"'.$sess_id.'","module":"'.$module.'","catid":"'.$_GET['catid'].'","userid":"'.$userid.'","siteid":"'.$siteid.'","dosubmit":"1","thumb_width":"'.$thumb_width.'","thumb_height":"'.$thumb_height.'","watermark_enable":"'.$watermark_enable.'","filetype_post":"'.$file_types_post.'","swf_auth_key":"'.$swf_auth_key.'","isadmin":"'.$isadmin.'","groupid":"'.$groupid.'"},
            file_size_limit:"'.$file_size_limit.'",
            file_types:"'.$file_types.'",
            file_types_description:"All Files",
            file_upload_limit:"'.$file_upload_limit.'",
            custom_settings : {progressTarget : "fsUploadProgress",cancelButtonId : "btnCancel"},

            button_image_url: "",
            button_width: 75,
            button_height: 28,
            button_placeholder_id: "buttonPlaceHolder",
            button_text_style: "",
            button_text_top_padding: 3,
            button_text_left_padding: 12,
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
            button_cursor: SWFUpload.CURSOR.HAND,

            file_dialog_start_handler : fileDialogStart,
            file_queued_handler : fileQueued,
            file_queue_error_handler:fileQueueError,
            file_dialog_complete_handler:fileDialogComplete,
            upload_progress_handler:uploadProgress,
            upload_error_handler:uploadError,
            upload_success_handler:uploadSuccess,
            upload_complete_handler:uploadComplete
            });
        })';
        return $init;
    }

본론 으로 돌아 갑 니 다.템 플 릿 swfupload.tpl.php 를 보 겠 습 니 다.
이 템 플 릿 은 js 를 사용 하여
  • 를 페이지 서명 으로 표시 합 니 다.우 리 는 firebug 로 우리 가 찾 을 swfupload 단 추 를 가 진 페이지 서명 id 를 찾 을 수 있 습 니 다.
    그 아 이 디 는 tabswf_1
    이것 은 div 코드 입 니 다.다음 과 같 습 니 다.

    <div id="div_swf_1" class="content pad-10 <?php echo $div_status?>">
                <div>
                    <div class="addnew" id="addnew">
                        <span id="buttonPlaceHolder"></span>
                    </div>
                    <input type="button" id="btupload" value="<?php echo L('start_upload')?>" onClick="swfu.startUpload();" />
                    <div id="nameTip" class="onShow"><?php echo L('upload_up_to')?><font color="red"> <?php echo $file_upload_limit?></font> <?php echo L('attachments')?>,<?php echo L('largest')?> <font color="red"><?php echo $file_size_limit?></font></div>
                    <div class="bk3"></div>

                    <div class="lh24"><?php echo L('supported')?> <font style="font-family: Arial, Helvetica, sans-serif"><?php echo str_replace(array('*.',';'),array('','、'),$file_types)?></font> <?php echo L('formats')?></div><input type="checkbox" id="watermark_enable" value="1" <?php if(isset($watermark_enable) &&$watermark_enable == 1) echo 'checked'?> onclick="change_params()"> <?php echo L('watermark_enable')?>
                </div>
                <div class="bk10"></div>
                <fieldset class="blue pad-10" id="swfupload">
                <legend><?php echo L('lists')?></legend>
                <ul class="attachment-list"  id="fsUploadProgress">
                </ul>
                </fieldset>
            </div>

    여기 서 span 이 있 는 것 을 보 았 습 니 다.   id 는 button Place Holder  프로필 에 이 줄 이 있 습 니 다 buttonplaceholder_id:"button Place Holder",분명 합 니 다.페이지 가 불 러 올 때 id 가 button Place Holder 인 요 소 는 JS 에서 swfupload 의 업로드 컨트롤 로 대 체 됩 니 다.
    다음 단 계 는 파일 을 선택 한 후에 swf 업로드 방법 을 터치 해 야 합 니 다.
    코드 에서 다음 코드 를 찾 을 수 있 습 니 다.이 안에 swfu.startUpload()방법 이 호출 되 었 습 니 다.이 방법 이 정 의 된 곳 은 swfupload.js 에 있 습 니 다.우 리 는 신경 쓸 필요 가 없습니다.

    <input type="button" id="btupload" value="<?php echo L('start_upload')?>" onClick="swfu.startUpload();" />
    이로써 swfupload 의 업로드 컨트롤 사용 방법 을 찾 았 습 니 다.
    왜 내 프로그램 에서 이 걸 호출 해? 
    우선 이 컨트롤 에 나타 난 템 플 릿 에 필요 한 파일

    <link href="<?php echo JS_PATH?>swfupload/swfupload.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/swfupload.js"></script>
    <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/fileprogress.js"></script>
    <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/handlers2.js"></script>
    <script type="text/javascript">
    <?php echo initupload($_GET['module'],$_GET['catid'],$args,$this->userid,$this->groupid,$this->isadmin)?>
    </script>
    코드 를 도입 해 야 합 니 다.
    그리고 우리 템 플 릿 에 swfupload 를 설치 하고 싶 은 곳 에 이러한 태그

    <span id="buttonPlaceHolder"></span>
    <input type="button" id="btupload" value="<?php echo L('start_upload')?>" onClick="swfu.startUpload();
    를 쓰 면 우 리 는 swfupload 를 우리 가 필요 로 하 는 곳 으로 도입 할 수 있 습 니 다.그 다음 에 업로드 등 기능 을 정상적으로 수행 할 수 있 습 니 다.
    그러나 이것 은 우리 의 요구 에 미 치지 못 한다.그리고 문제 가 하나 있다.우 리 는 서 류 를 신마 에 게 올 렸 다.그러면 우 리 는 서 류 를 신마 에 게 올 린 곳 을 찾 아 보 자.
    설정 파일(initupload 함수 로 출력 한)에 이 줄

    upload_url:"'.APP_PATH.'index.php?m=attachment&c=attachments&a=swfupload&dosubmit=1",
    이 있 습 니 다.
    이곳 은 내 가 이전에 관심 을 갖 지 않 았 던 if 안의 물건 이다.
    꺼 내 봐

    if( $_POST['swf_auth_key'] != md5(pc_base::load_config('system','auth_key').$_POST['SWFUPLOADSESSID']) || ($_POST['isadmin']==0 && !$grouplist[$_POST['groupid']]['allowattachment'])) exit();
                pc_base::load_sys_class('attachment','',0);
                $attachment = new attachment($_POST['module'],$_POST['catid'],$_POST['siteid']);
                $attachment->set_userid($_POST['userid']);
                $aids = $attachment->upload('Filedata',$_POST['filetype_post'],'','',array($_POST['thumb_width'],$_POST['thumb_height']),$_POST['watermark_enable']);
                if($aids[0]) {
                    $filename= (strtolower(CHARSET) != 'utf-8') ? iconv('gbk', 'utf-8', $attachment->uploadedfiles[0]['filename']) : $attachment->uploadedfiles[0]['filename'];
                    if($attachment->uploadedfiles[0]['isimage']) {
                        echo $aids[0].','.$this->upload_url.$attachment->uploadedfiles[0]['filepath'].','.$attachment->uploadedfiles[0]['isimage'].','.$filename;
                    } else {
                        $fileext = $attachment->uploadedfiles[0]['fileext'];
                        if($fileext == 'zip' || $fileext == 'rar') $fileext = 'rar';
                        elseif($fileext == 'doc' || $fileext == 'docx') $fileext = 'doc';
                        elseif($fileext == 'xls' || $fileext == 'xlsx') $fileext = 'xls';
                        elseif($fileext == 'ppt' || $fileext == 'pptx') $fileext = 'ppt';
                        elseif ($fileext == 'flv' || $fileext == 'swf' || $fileext == 'rm' || $fileext == 'rmvb') $fileext = 'flv';
                        else $fileext = 'do';
                        echo $aids[0].','.$this->upload_url.$attachment->uploadedfiles[0]['filepath'].','.$fileext.','.$filename;
                    }
                    exit;
                } else {
                    echo '0,'.$attachment->error();
                    exit;
    이 안에 몇 줄 이 있 는 지.
    우선 시스템 의 attachment 류 를 불 러 왔 습 니 다.그리고 그 방법 을 사 용 했 습 니 다.
    프로그램 이 업로드 에 성공 하여 echo 작업 을 했 습 니 다.돌아 오 는 것 은?   번호,업 로드 된 주소,확장자,파일 이름 을 되 돌려 줍 니 다.
    이 물건 들 은 누구 에 게 쓰 는 것 입 니까?   우 리 는 프로필 을 다시 보 러 가 야 한다.
    설정 파일 중 하 나 는 업로드 과정 에서 각 이벤트 가 실 행 될 방법 입 니 다.  올 리 기 시작 한 게 있어 요.올 리 기 성공 한 게 있 고 올 리 기 실패 한 게 있어 요.등등.
    저희 가 볼 수 있 는 방법 은 file 입 니 다.dialog_complete_handler:fileDialogComplete,
    사실 이것들 은 swfupload 의 범주 로 업그레이드 되 었 습 니 다.관심 이 있 으 면 연구 할 수 있 습 니 다.
    그리고 우 리 는 phpcms/static/swfupload/handler.js 에서 이 방법 을 찾 았 다.
    업로드 에 성공 한 것 을 보고 echo 에서 나 온 데이터 가 분석 되 었 습 니 다.
    해석 방법 은 다음 과 같다

    function att_show(serverData,file)
    {
        var serverData = serverData.replace(/<div.*?<\/div>/g,'');
        var data = serverData.split(',');
        var id = data[0];
        var src = data[1];
        var ext = data[2];
        var filename = data[3];
        if(id == 0) {
            alert(src)
            return false;
        }
        if(ext == 1) {
            var img = '<a href="javascript:;" onclick="javascript:att_cancel(this,'+id+',\'upload\')" class="on"><div class="icon"></div><img src="'+src+'" width="80" imgid="'+id+'" path="'+src+'" title="'+filename+'"/></a>';
        } else {
            var img = '<a href="javascript:;" onclick="javascript:att_cancel(this,'+id+',\'upload\')" class="on"><div class="icon"></div><img src="statics/images/ext/'+ext+'.png" width="80" imgid="'+id+'" path="'+src+'" title="'+filename+'"/></a>';
        }
        $.get('index.php?m=attachment&c=attachments&a=swfupload_json&aid='+id+'&src='+src+'&filename='+filename);
        $('#fsUploadProgress').append('<li><div id="attachment_'+id+'" class="img-wrap"></div></li>');
        $('#attachment_'+id).html(img);
        $('#att-status').append('|'+src);
        $('#att-name').append('|'+filename);
    }
    .이 방법의 목적 은 id 가 fsuuploadprogress 요소 에 우리 가 업로드 한 성공 적 인 첨부 파일 을 추가 하 는 것 이다.그러나 우 리 는 파일 이 어디로 갔 는 지 찾 을 수 없다.
    중요 한 곳 이 왔 습 니 다.swfupload 방법 에 attachment 시스템 클래스 의 인 스 턴 스 가 있 지 않 습 니까?
    진정 으로 첨부 파일 을 업로드 하 는 것 은 여기에서 이 루어 집 니 다.우 리 는 attachment 안의 upload 방법 을 호출 하여 파일 의 업 로드 를 실현 합 니 다.
    이 attachment 파일 에 있 는 upload 방법 은 시스템 클래스,즉 pc ms/libs/classes/attachment.class.php 에 있 습 니 다.
    이 클래스 에서 upload 방법 을 찾 을 수 있 습 니 다.이 줄

    $this->savepath = $this->upload_root.$this->upload_dir.date('Y/md/');
    은 당연히 업 로드 된 디 렉 터 리 를 지정 한 것 입 니 다.파일 이름 은 getname 방법 을 통 해 얻 을 수 있 습 니 다.
    여기까지 우 리 는 생각 을 정리 했다.
    시스템 은 이렇게 작 동 합 니 다.
    먼저 템 플 릿 에서 swfupload(프로필 은 함수 로 생 성 됨)->파일 업로드->attachment 모듈 의 swfupload 방법 처리(시스템 의 attachment 클래스 의 upload 방법 으로 첨부 파일 을 반복 적 으로 업로드 합 니 다.결 과 를 swfupload 방법 으로 되 돌려 줍 니 다)->처리 결 과 는 swfupload 방법(fileDialogComplete)을 통 해 페이지 에 되 돌려 줍 니 다.
    위 에서 우 리 는 템 플 릿 에 swfupload 를 도입 하 는 것 을 실 현 했 습 니 다.그러나 우리 가 사용 하 는 프로필 과 첨부 파일 을 업로드 하 는 방법 등 은 모두 시스템 이 원래 가지 고 있 던 것 입 니 다.제 가 원 하 는 디 렉 터 리 구조 와 파일 이름 을 실현 할 수 없습니다.어떻게 해 야 합 니까?
    고치다
    어떻게 바 꾸 는 지,우선 설정 파일 을 고 쳐 야 합 니 다.자신의 모듈 에 있 는 functions 폴 더 에 자신의 함 수 를 만 듭 니 다.우 리 는 자신의 함수 이름 파일 을 global.func.php 라 고 명명 하면 시스템 은 auto 를 통 해load 우리 함수 불 러 오기
    들 어가 서 시스템 에 있 는 attachment 모듈 functions 폴 더 아래 의 global.func.php 에 있 는 initupload 함수 전 체 를 복사 합 니 다.그 중의 한 줄

    upload_url:"'.APP_PATH.'index.php?m= &c= &a= &dosubmit=1",
    만 수정 하면 파일 이 컨트롤 러 아래 에 제출 되 고 우리 가 쓴 방법 을 호출 합 니 다.
    그리고 저희 가 시스템 의 attachment 류 를 바 꾸 러 갑 니 다.  우 리 는 자신의 모듈 에 있 는 classes 폴 더 아래 에 my attachment.class.phop 을 만 듭 니 다.
    우리 만 의 클래스 를 쓰 세 요.시스템 의 attachment 클래스 를 통합 하 세 요.(기억 하 세 요.개인 적 인 방법 copy 이리 오 세 요.)몇 줄 을 수정 해 야 합 니 다.우선 upload 방법 에 있 는 업로드 디 렉 터 리 를 바 꾸 세 요.그 다음 에 파일 이름 을 바 꾸 는 방법 입 니 다.

    function upload($field, $alowexts = '', $maxsize = 0, $overwrite = 0,$thumb_setting = array(), $watermark_enable = 1) {
            if(!isset($_FILES[$field])) {
                $this->error = UPLOAD_ERR_OK;
                return false;
            }
            if(empty($alowexts) || $alowexts == '') {
                $site_setting = $this->_get_site_setting($this->siteid);
                $alowexts = $site_setting['upload_allowext'];
            }
            $fn = $_GET['CKEditorFuncNum'] ? $_GET['CKEditorFuncNum'] : '1';

            $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 모듈 의 attachment 컨트롤 러 안의 swfupload 방법 을 참조 하여 수정 할 수 있 습 니 다.
    이로써 저 는 제 목적 을 완 성 했 습 니 다.시스템 파일 디 렉 터 리 를 바 꾸 지 않 는 토대 에서 제 가 원 하 는 파일 업로드 기능 을 완 성 했 습 니 다.
  • 좋은 웹페이지 즐겨찾기