dwz xheditor编辑器文件上传

来源:互联网 发布:淘宝网首页登录电脑版 编辑:程序博客网 时间:2024/05/28 14:56

转载地址:http://blog.csdn.net/sean_cd/article/details/8027315


    client------------------------      <form method="post" action="/Articles/articleEdit" class="pageForm required-validate" enctype="multipart/form-data"  onsubmit="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;          }         


0 0