dwz xheditor编辑器文件上传


client------------------------
<form method="post" action="/Articles/articleEdit" class="pageForm required-validate" enctype="multipart/form-data"  οnsubmit="return iframeCallback(this, dialogAjaxDone)" >


		<textarea name="fld_content" rows="23" cols="83"
						class="editor" tools="Fullscreen,Source,Preview,Print,|,SelectAll,Cut,Copy,Paste,Pastetext,Blocktag,|,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,|,Removeformat
						Align,List,Outdent,Indent,Link,Unlink,Anchor,Img,Hr,Table"
						skin="default"
						upLinkUrl="" upLinkExt="zip,rar,txt,doc,docx"
						upImgUrl="/FileUpload/doXheditorUpload?flag=img" 
						upImgExt="jpg,jpeg,gif,png"
						upMultiple=6
						upFlashUrl="" upFlashExt="swf">{$info.fld_content}								 	
	        </textarea>


server-----------------------------

    public function action_doXheditorUpload()
    {
        global $CONFIG;
        $cdnServer = $CONFIG['CDNServer'];
        $cdnServerInfo = $cdnServer['IC'];
        //generator saved file name
        $ymd = date("Ymd");
        $cdnFilePath = "ic/images/".$ymd;            
        if (empty($_FILES) === false) {
            $fileName = $_FILES['filedata']['name'];
            $tmp_name = $_FILES['filedata']['tmp_name'];
            $cdnFileName = $this->generateFileNameByTime($fileName);
            if(AdminLib_CDNUploadUtility::moveFileToCdn($tmp_name, $cdnFilePath, $cdnFileName, $cdnServerInfo, $imgUrl)){            
                header('Content-type: text/html; charset=UTF-8');
                exit(json_encode(array('err' => 0, 'msg' => $imgUrl)));
            }
        }
    }


    static public function moveFileToCdn($sLocalFile, $sCDNFilePath, $sCDNFileName,  $cdn_server_info, & $sCDNFileFullUrl) {
        $ret = false;
        try
        {
            $local_filefullname = $sLocalFile; //resolveUrl($sFileDir) . $sFileName;
            $fp = @fopen($local_filefullname , 'r');
            if(!$fp) {
                fb("no local: $local_filefullname", FirePHP::TRACE);                
                return false;
            }
            
            if(!is_array($sCDNFilePath))
                $sCDNFilePath = explode ("/", $sCDNFilePath);

            $conn_id = @ftp_connect($cdn_server_info['ftp_host'], $cdn_server_info['ftp_port'], 15);

            if($conn_id)
            {
                $ret = @ftp_login($conn_id, $cdn_server_info['ftp_username'], $cdn_server_info['ftp_password']);
                if($ret)
                {
                    @ftp_pasv($conn_id, true);

                    if(isset($cdn_server_info['ftp_path']))
                    {
                        $path = trim($cdn_server_info['ftp_path']);
                        $path = rtrim($path, '/');
                        try
                        {
                            //there is a WARNING to EXCEPTION handler in system ....
                            $ret = @ftp_chdir($conn_id, $path);
                        }catch(Exception $ex){}
                    }
                    
                    foreach($sCDNFilePath as $dirname)
                    {
                        if($ret)
                        {
                            $chdir_ok = false;
                            try
                            {
                                //there is a WARNING to EXCEPTION handler in system ....
                                $chdir_ok = @ftp_chdir($conn_id, $dirname);
                            }catch(Exception $ex){}

                            if( ! $chdir_ok )
                            {
                                $ret = $ret && (ftp_mkdir($conn_id, "$dirname") !== false);
                                $ret = $ret && ftp_chdir($conn_id, "$dirname");
                            }
                        }
                    }

                    $ret = $ret && @ftp_fput($conn_id, $sCDNFileName, $fp, FTP_BINARY);

                    if ($ret)
                    {
                        $sCDNFileFullUrl = $cdn_server_info['http_base_url'] . join("/", $sCDNFilePath) . "/" . $sCDNFileName;                           
                    }
                   
                }
                @ftp_close($conn_id);
            }
            @fclose($fp);
        }catch(Exception $ex){
            monolog_info('Thumb/koubei', "Move CDN failed,{$sLocalFile}.\r\n");
        }
        return $ret;
    }
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值