帝国CMS实现d/file/与网站分离
第一步、
打开e\class\connect.php搜索 if($link)
162行左右
在上面添加:eDoPostFileServer();
第二步、
打开e\class\connect.php搜索//--------------- 公共 ---------------
169行左右
在上面添加:
PHP Code复制内容到剪贴板
- //--------------- 远程发布 ---------------
- //远程附件发布
- function eDoPostFileServer(){
- global $efileftp,$efileftp_fr,$efileftp_dr,$public_r;
- if(emptyempty($public_r['openfileserver'])||!($efileftp_fr[0]||$efileftp_dr[0]))
- {
- return '';
- }
- if(!defined('InEmpireCMSFtp'))
- {
- include(ECMS_PATH.'e/class/ftp.php');
- }
- $pr=ReturnPostFtpInfo(1);
- $efileftp=new EmpireCMSFTP();
- $efileftp->fconnect($pr['ftphost'],$pr['ftpport'],$pr['ftpusername'],$pr['ftppassword'],$pr['ftppath'],$pr['ftpssl'],$pr['ftppasv'],$pr['ftpmode'],$pr['ftpouttime']);
- $basepath=$pr['ftppath'].'/';
- if($efileftp_fr[0])
- {
- $path=ReturnPostFtpFilePath(ReturnPostFtpFilename($efileftp_fr[0]));
- $efileftp->ftp_mkdirs($basepath,$path);
- $count=count($efileftp_fr);
- for($i=0;$i<$count;$i++)
- {
- $lfile=$efileftp_fr[$i];
- $hfile=$basepath.ReturnPostFtpFilename($efileftp_fr[$i]);
- $efileftp->fTranFile($hfile,$lfile,0,0);
- }
- }
- if($efileftp_dr[0])
- {
- $dcount=count($efileftp_dr);
- for($di=0;$di<$dcount;$di++)
- {
- $dhfile=$basepath.ReturnPostFtpFilename($efileftp_dr[$di]);
- $efileftp->fDelFile($dhfile);
- }
- }
- $efileftp->fExit();
- }
- //返回发布FTP信息
- function ReturnPostFtpInfo($pid){
- global $empire,$dbtbpre;
- $r=$empire->fetch1("select * from {$dbtbpre}enewspostserver where pid='$pid'");
- return $r;
- }
- //返回远程实际文件地址
- function ReturnPostFtpFilename($file){
- $file=str_replace(ECMS_PATH,'',$file);
- $file=str_replace('../','',$file);
- $file=str_replace('d/file/','',$file);
- return $file;
- }
- //返回远程实际目录
- function ReturnPostFtpFilePath($file){
- $r=explode('/',$file);
- $count=count($r)-1;
- $path=substr($file,0,strlen($file)-strlen($r[$count])-1);
- return $path;
- }
第三步、
打开e\admin\SetEnews.php搜索<tbody id="setfileserver" style="display:none">
1117行左右
将:
<tbody id="setfileserver" style="display:none">
</tbody>
替换为:
PHP Code复制内容到剪贴板
- <tr>
- <td height="25" colspan="2" class="header">远程附件设置</td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">启用远程附件</td>
- <td height="25" bgcolor="#FFFFFF"><input type="radio" name="openfileserver" value="1"<?=$r['openfileserver']==1?' checked':''?> onclick="setfileserver.style.display='';">
- 是
- <input type="radio" name="openfileserver" value="0"<?=$r['openfileserver']==0?' checked':''?> onclick="setfileserver.style.display='none';">
- 否 </td>
- </tr>
- <tbody id="setfileserver" style="display:none">
- <tr>
- <td height="25" bgcolor="#FFFFFF">启用 SSL 连接</td>
- <td height="25" bgcolor="#FFFFFF"><input type="radio" name="fs_ftpssl" value="1"<?=$fsr[ftpssl]==1?' checked':''?>>
- 是
- <input type="radio" name="fs_ftpssl" value="0"<?=$fsr[ftpssl]==0?' checked':''?>>
- 否 </td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">被动模式(pasv)连接</td>
- <td height="25" bgcolor="#FFFFFF"><input type="radio" name="fs_ftppasv" value="1"<?=$fsr[ftppasv]==1?' checked':''?>>
- 是
- <input type="radio" name="fs_ftppasv" value="0"<?=$fsr[ftppasv]==0?' checked':''?>>
- 否 </td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">FTP服务器地址</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_ftphost" type="text" id="fs_ftphost" value="<?=$fsr[ftphost]?>" size="38">
- 端口:
- <input name="fs_ftpport" type="text" id="fs_ftpport" value="<?=$fsr[ftpport]?>" size="4"></td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">FTP用户名</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_ftpusername" type="text" id="fs_ftpusername" value="<?=$fsr[ftpusername]?>" size="38">
- </td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">FTP密码</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_ftppassword" type="password" id="fs_ftppassword" size="38">
- <font color="#666666">(不修改密码请留空) </font></td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">传送模式</td>
- <td height="25" bgcolor="#FFFFFF"><input type="radio" name="fs_ftpmode" value="1"<?=$fsr[ftpmode]==1?' checked':''?>>
- ASCII
- <input type="radio" name="fs_ftpmode" value="0"<?=$fsr[ftpmode]==0?' checked':''?>>
- 二进制</td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">FTP 传输超时时间</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_ftpouttime" type="text" id="fs_ftpouttime" value="<?=$fsr[ftpouttime]?>" size="38">
- 秒<font color="#666666">(0为服务器默认)</font></td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">远程附件目录</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_ftppath" type="text" id="fs_ftppath" value="<?=$fsr[ftppath]?>" size="38">
- <font color="#666666">(目录结尾不要加斜杠“/”,空为根目录)</font></td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">远程访问地址</td>
- <td height="25" bgcolor="#FFFFFF"><input name="fs_purl" type="text" id="fs_purl" value="<?=$fsr[purl]?>" size="38">
- <font color="#666666">(结尾需加“/”,如:http://file.phome.net/)</font></td>
- </tr>
- <tr>
- <td height="25" bgcolor="#FFFFFF">测试FTP服务器</td>
- <td height="25" bgcolor="#FFFFFF"><input type="submit" name="Submit3" value="测试FTP服务器" onClick="document.form1.enews.value='CheckFileServerFtp';document.form1.action='SetEnews.php';document.form1.target='checkftpiframe';"> <font color="#666666">(无需保存设置即可测试,请在测试通过后再保存)</font>
- </td>
- </tr>
- </tbody>