全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1238|回复: 7
打印 上一主题 下一主题

请教大神个PHP代码的问题

[复制链接]
跳转到指定楼层
1#
发表于 2017-9-24 11:29:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 rookiesoft 于 2017-9-24 16:09 编辑

Google自己解决了。。。。。



DEDECMS 5.7后台上传软件的源文件

没有金币,20元请吃碗面行吗?


本来这个页面是点上传之后上传一个软件,然后页面刷新后显示该目录下面的软件,刚上传的文件名字显示为红色,这时候再随便点击一个链接窗口关闭,点链接的路径自动返回到添加软件页面上软件地址框里,想问一下怎么实现上传软件后不显示软件列表了,直接将刚上传的文件路径返回到软件添加页的地址框里?
这段代码是返回的JAVASCRIPT
  1. <SCRIPT language='JavaScript'>
  2. function nullLink()
  3. {
  4.         return;
  5. }

  6. function ReturnValue(reimg)
  7. {
  8.     if(window.opener.document.<?php echo $f?> != null)
  9.         {
  10.                  window.opener.document.<?php echo $f?>.value=reimg;
  11.         }
  12.          
  13.     var funcNum = <?php echo isset($CKEditorFuncNum)? $CKEditorFuncNum : 1;?>;
  14.         if(window.opener.CKEDITOR != null && funcNum != 1)
  15.         {
  16.                
  17.                 window.opener.CKEDITOR.tools.callFunction(funcNum, reimg);
  18.                
  19.         }
  20.         window.close();
  21. }
  22. </SCRIPT>
复制代码


这里这句判断出刚上传的软件
  1.     else if(preg_match("#\.(zip|rar|tgr.gz)#i", $file))
  2.     {
  3.         if($file==$comeback) $lstyle = " style='color:red' ";
  4.         else  $lstyle = "";

  5.         $reurl = "$activeurl/$file";

  6.         $reurl = preg_replace("#^\.\.#", "", $reurl);
复制代码


请问代码应该怎么改?没学过PHP,但这个功能能减小点工作量,求会写PHP的帮忙看看,谢谢。

界面:
QQ截图20170924113312.png (62.86 KB, 下载次数: 0)
select_soft.php代码:
  1. <?php
  2. /**
  3. * 软件选择框
  4. *
  5. * @version        $Id: select_soft.php 1 9:43 2010年7月8日Z tianya $
  6. * @package        DedeCMS.Dialog
  7. * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
  8. * @license        http://help.dedecms.com/usersguide/license.html
  9. * @link           http://www.dedecms.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. if(empty($activepath))
  13. {
  14.     $activepath = '';
  15. }
  16. $activepath = str_replace('.','',$activepath);
  17. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  18. if(strlen($activepath) < strlen($cfg_soft_dir))
  19. {
  20.     $activepath = $cfg_soft_dir;
  21. }
  22. $inpath = $cfg_basedir.$activepath;
  23. $activeurl = '..'.$activepath;
  24. if(empty($f))
  25. {
  26.     $f='form1.enclosure';
  27. }
  28. if (!is_dir($inpath) )
  29. {
  30.     die('No Exsits Path');
  31. }
  32. if(empty($comeback))
  33. {
  34.     $comeback = '';
  35. }
  36. $addparm = '';
  37. if (!empty($CKEditor))
  38. {
  39.     $addparm = '&CKEditor='.$CKEditor;
  40. }
  41. if (!empty($CKEditorFuncNum))
  42. {
  43.     $addparm .= '&CKEditorFuncNum='.$CKEditorFuncNum;
  44. }
  45. if (!empty($noeditor))
  46. {
  47.     $addparm .= '&noeditor=yes';
  48. }
  49. ?>
  50. <html>
  51. <head>
  52. <meta http-equiv='Content-Type' content='text/html; charset=<?php echo $cfg_soft_lang; ?>'>
  53. <title>软件管理器</title>
  54. <link href='../../plus/img/base.css' rel='stylesheet' type='text/css'>
  55. <style>
  56. .linerow {border-bottom: 1px solid #CBD8AC;}
  57. </style>
  58. </head>
  59. <body background='img/allbg.gif' leftmargin='5' topmargin='0'>
  60. <SCRIPT language='JavaScript'>
  61. function nullLink()
  62. {
  63.         return;
  64. }

  65. function ReturnValue(reimg)
  66. {
  67.     if(window.opener.document.<?php echo $f?> != null)
  68.         {
  69.                  window.opener.document.<?php echo $f?>.value=reimg;
  70.         }
  71.          
  72.     var funcNum = <?php echo isset($CKEditorFuncNum)? $CKEditorFuncNum : 1;?>;
  73.         if(window.opener.CKEDITOR != null && funcNum != 1)
  74.         {
  75.                
  76.                 window.opener.CKEDITOR.tools.callFunction(funcNum, reimg);
  77.                
  78.         }
  79.         window.close();
  80. }
  81. </SCRIPT>
  82. <table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#CBD8AC' align="center">
  83. <tr>
  84. <td colspan='3' bgcolor='#E8F1DE' background="img/tbg.gif" height='28'>
  85.         <form action='select_soft_post.php' method='POST' enctype="multipart/form-data" name='myform'>
  86.                 <input type='hidden' name='activepath' value='<?php echo $activepath?>' />
  87.                 <input type='hidden' name='f' value='<?php echo $f?>' />
  88.                 <input type='hidden' name='job' value='upload' />
  89.           &nbsp;上 传: <input type='file' name='uploadfile' size='25' />
  90.           &nbsp;
  91.           改 名:<input type='test' name='newname' style='width:90px' />
  92.           &nbsp;
  93.           <input type='submit' name='sb1' value='确定' />
  94.         </form>
  95. </td>
  96. </tr>
  97. <tr bgcolor='#FFFFFF'>
  98. <td colspan='3'>
  99. <!-- 开始文件列表  -->
  100. <table width='100%' border='0' cellspacing='0' cellpadding='2'>
  101. <tr bgcolor="#CCCCCC" height="24">
  102. <td width="55%" align="center" background="img/wbg.gif" class='linerow'><strong>点击名称选择文件</strong></td>
  103. <td width="15%" align="center" bgcolor='#EEF4EA' class='linerow'><strong>文件大小</strong></td>
  104. <td width="30%" align="center" background="img/wbg.gif" class='linerow'><strong>最后修改时间</strong></td>
  105. </tr>
  106. <?php
  107. $dh = dir($inpath);
  108. $ty1 = $ty2 = '';
  109. while($file = $dh->read())
  110. {
  111.     //-----计算文件大小和创建时间
  112.     if($file != "." && $file != ".." && !is_dir("$inpath/$file"))
  113.     {
  114.         $filesize = filesize("$inpath/$file");
  115.         $filesize = $filesize / 1024;
  116.         if($filesize != "")
  117.         if($filesize < 0.1){
  118.             @list($ty1, $ty2) = split("\.", $filesize);
  119.             $filesize = $ty1.".".substr($ty2, 0, 2);
  120.         }
  121.         else{
  122.             @list($ty1, $ty2) = split("\.", $filesize);
  123.             $filesize = $ty1.".".substr($ty2, 0, 1);
  124.         }
  125.         $filetime = filemtime("$inpath/$file");
  126.         $filetime = MyDate("Y-m-d H:i:s", $filetime);
  127.     }
  128.     //------判断文件类型并作处理
  129.     if($file == ".") continue;
  130.     else if($file == "..")
  131.     {
  132.         if($activepath == "") continue;
  133.         $tmp = preg_replace("#[\/][^\/]*$#i", "", $activepath);
  134.         $line = "\n<tr height='24'>
  135.     <td class='linerow'> <a href='select_soft.php?f=$f&activepath=".urlencode($tmp).$addparm."'><img src=img/dir2.gif border=0 width=16 height=16 align=absmiddle>上级目录</a></td>
  136.     <td colspan='2' class='linerow'> 当前目录:$activepath</td>
  137.     </tr>\r\n";
  138.         echo $line;
  139.     }
  140.     else if(is_dir("$inpath/$file"))
  141.     {
  142.         if(preg_match("#^_(.*)$#i", $file)) continue; #屏蔽FrontPage扩展目录和linux隐蔽目录
  143.         if(preg_match("#^\.(.*)$#i", $file)) continue;
  144.         $line = "\n<tr height='24'>
  145.    <td bgcolor='#F9FBF0' class='linerow'>
  146.     <a href=select_soft.php?f=$f&activepath=".urlencode("$activepath/$file").$addparm."><img src=img/dir.gif border=0 width=16 height=16 align=absmiddle>$file</a>
  147.    </td>
  148.    <td class='linerow'>-</td>
  149.    <td bgcolor='#F9FBF0' class='linerow'>-</td>
  150.    </tr>";
  151.         echo "$line";
  152.     }
  153.     else if(preg_match("#\.(zip|rar|tgr.gz)#i", $file))
  154.     {
  155.         if($file==$comeback) $lstyle = " style='color:red' ";
  156.         else  $lstyle = "";

  157.         $reurl = "$activeurl/$file";

  158.         $reurl = preg_replace("#^\.\.#", "", $reurl);
  159.         if($cfg_remote_site=='Y' && $remoteuploads == 1)
  160.         {
  161.             $reurl  = $remoteupUrl.$reurl;
  162.         } else {
  163.             $reurl = $reurl;
  164.         }

  165.         $line = "\n<tr height='24'>
  166.    <td class='linerow' bgcolor='#F9FBF0'>

  167.      <a href="javascript:ReturnValue('$reurl');" $lstyle><img src=img/zip.gif border=0 width=16 height=16 align=absmiddle>$file</a>
  168.    </td>
  169.    <td class='linerow'>$filesize KB</td>
  170.    <td align='center' class='linerow' bgcolor='#F9FBF0'>$filetime</td>
  171.    </tr>";
  172.         echo "$line";
  173.     }
  174.     else
  175.     {
  176.         if($file==$comeback) $lstyle = " style='color:red' ";
  177.         else  $lstyle = '';

  178.         $reurl = "$activeurl/$file";

  179.         $reurl = preg_replace("#^\.\.#", "", $reurl);
  180.         if($cfg_remote_site=='Y' && $remoteuploads == 1)
  181.         {
  182.             $reurl  = $remoteupUrl.$reurl;
  183.         } else {
  184.             $reurl = $reurl;
  185.         }

  186.         $line = "\n<tr height='24'>
  187.    <td class='linerow' bgcolor='#F9FBF0'>
  188.      <a href="javascript:ReturnValue('$reurl');" $lstyle><img src=img/exe.gif border=0 width=16 height=16 align=absmiddle>$file</a>
  189.    </td>
  190.    <td class='linerow'>$filesize KB</td>
  191.    <td align='center' class='linerow' bgcolor='#F9FBF0'>$filetime</td>
  192.    </tr>";
  193.         echo "$line";
  194.     }
  195. }//End Loop
  196. $dh->close();
  197. ?>
  198. <!-- 文件列表完 -->
  199. </table></td></tr>
  200. <tr><td colspan='3' bgcolor='#E8F1DE' height='26'>&nbsp;请点击要选择的文件,红色字样的为刚上传的文件。</td></tr>
  201. </table>
  202. </body>
  203. </html>
复制代码
2#
发表于 2017-9-24 11:56:43 来自手机 | 只看该作者
帮顶,消灭零回复
3#
发表于 2017-9-24 12:01:08 | 只看该作者
我以前那么简单的问题都悬赏了370金币,所以…
4#
发表于 2017-9-24 12:11:36 | 只看该作者
贴这么长的源码,没人高兴看的
5#
发表于 2017-9-24 12:39:50 | 只看该作者
出钱就有人答了
6#
 楼主| 发表于 2017-9-24 12:47:55 来自手机 | 只看该作者
没有金币,解决了请大佬吃碗面
7#
发表于 2017-9-24 12:48:26 | 只看该作者
no money no talk
8#
发表于 2017-9-24 13:10:15 | 只看该作者
大哥 那么长的代码 没点金币谁帮你看啊
社会很现实的好伐
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-12 11:58 , Processed in 0.070166 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表