急!!!请大家帮忙看一段程序!

chunyou128 2008-11-07 02:55:06
预想结果:列出mytest.php所在路径的所有目录文件,如果双击的是目录,会列出此目录下的目录及文件,如果点击up,返回上级目录,并列出上级目录下的目录及文件,请大家看看我的程序,为啥没能实现?
<html>
<head>
<title>test</title>
<script language=javascript>
<!--

function updir(obj)
{
dirval = "mytest.php?flag=2&dir=";
dirval += obj;
alert(dirval);
location.replace(dirval);
}

//停止拖动;
function clickselect(obj)
{
fromList = eval(obj);

for (i=0;i<fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
var dirval = fromList.options[i].value;
var url = dirval;
dirval = "mytest.php?dir=";
dirval += url;
location.replace(dirval);
break;
}
}
}

function copyToList(from,to)
{
fromList = eval(from);
toList = eval(to);
if (toList.options.length > 0 && toList.options[0].value == 'temp')
{
toList.options.length = 0;
}
var sel = false;
for (i=0;i<fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
sel = true;
if (current.value == 'temp')
{
alert ('你不能选择这一项!');
return;
}
txt = current.text;
val = current.value;
toList.options[toList.length] = new Option(txt,val);
}
}
if (!sel) alert ('你还没有选择任何项');
}

function del(from)
{
fromList = eval(from);
var sel = false;
for (i=0;i<fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
sel = true;
if (current.value == 'temp')
{
alert ('你不能选择这一项!');
return;
}
txt = current.text;
val = current.value;
fromList.options[i] = null;
i--;
}
}
if (!sel) alert ('你还没有选择任何项');
}
//-->
</script>
</head>
<body>
<select name="possible" size="8" MULTIPLE width=120 ondblclick="clickselect(this)" >
<?

if($flag==2) {
$cut1=strrpos($dir,"/");
$dir=trim(substr($dir,0,$cut1));
echo "<SCRIPT LANGUAGE=javascript>";
echo "alert(\"$dir\")";
echo "</SCRIPT>";
}

exec("/bin/ls $dir > /tmp/syslog");
$logInf = file("/tmp/syslog");
$logInfNum = count($logInf);

for ($i=0; $i<$logInfNum; $i++){
$value = $dir."/";
echo "<option value=\"$value$logInf[$i]\"";
echo ">$logInf[$i]";
}
?>
</select>
<td width="20%" align="center">
<a <? echo "href=\"javascript:updir('$dir')\"";?> >up</a><br>
<a href="javascript:copyToList('possible','possible0')">add</a><br>
<br><a href="javascript:del('possible0')">del</a></td>
<td width="40%" align="center">
<select name="possible0" size="8" MULTIPLE width=120 >
</select>
</body>
</html>

...全文
240 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
chunyou128 2008-11-11
  • 打赏
  • 举报
回复
(1)调试时,注意重启一下浏览器,这也是蛮重要的(2)刷新时,注意把地址自己!(3)谢谢大家!!!
chunyou128 2008-11-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jakey9826 的回复:]
//要获取dir从$_GET里
//要设置起始的dir
extract($_GET);
if($dir == "")
$dir = "...";// ...替换为起始路径,明白
[/Quote]
你好,起始路径是不是指单个文件名?如:mytest.php(就是我上面的那段程序的名字),对吗?
chunyou128 2008-11-10
  • 打赏
  • 举报
回复
怎么都没测出问题呢?除了双击进入tmp路径里,能正确tmp下的目录外,其他的都不能正确显示,难道是环境问题?郁闷了...
Longinc 2008-11-10
  • 打赏
  • 举报
回复
帮顶
chunyou128 2008-11-10
  • 打赏
  • 举报
回复
chinmo 2008年11月10日 16点37分20秒 说:
var strM = "/url/";
alert(strM.replace(/\//,""));
chinmo 2008年11月10日 16点37分26秒 说:
不要全局即可
chinmo 2008年11月10日 16点37分39秒 说:
去掉全局匹配
  • 打赏
  • 举报
回复
dirval += url.replace(/\//,"");
把全局去掉即可
chunyou128 2008-11-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chunyou128 的回复:]
dirval += url.replace(/\//g,"");http://topic.csdn.net/u/20081110/13/63e60713-f268-4fe7-9e3c-78b55e587b55.html
[/Quote]
如过有两层目录就不行了!如:
mytest.php
audit/yyc/yyc.php
双击audit,可以正确显示,再双击yyc就不行了ie地址变成:http://192.168.20.254/mytest.php?dir=audityyc
---------------------------------------------------
yyc前的斜杠也被去掉了...
chenping1984 2008-11-10
  • 打赏
  • 举报
回复
读取一个文件夹的 所有文件名 不是用 file的

用 dir 然后遍历
例子:
$dir = dir($path);
while(false !== ($name =$dir->read())){
if($name != '..' && $name != '..'){
echo $name;
}
}这样才是输出某个文件夹的 文件名。
chunyou128 2008-11-10
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
很简单的问题
可惜我的电脑现在没有PHP环境

只要按你现在的情况特征,用replace去掉多余的/即可,想去掉/在JS里用\/这样来匹配
程序猿之殇 2008-11-10
  • 打赏
  • 举报
回复
起始路径就是你要管理的目录.
mlsml 2008-11-09
  • 打赏
  • 举报
回复
没看出问题
zgycsmb 2008-11-07
  • 打赏
  • 举报
回复
学习。。
whalefish2001 2008-11-07
  • 打赏
  • 举报
回复
呵呵,很复杂,有空研究一下。
phpboy 2008-11-07
  • 打赏
  • 举报
回复
测试了一下,没看出毛病
顶一下楼上...!
[Quote=引用 2 楼 jakey9826 的回复:]
//要获取dir从$_GET里
//要设置起始的dir
extract($_GET);
if($dir == "")
$dir = "...";// ...替换为起始路径,明白
[/Quote]
程序猿之殇 2008-11-07
  • 打赏
  • 举报
回复
//要获取dir从$_GET里
//要设置起始的dir
extract($_GET);
if($dir == "")
$dir = "...";// ...替换为起始路径,明白
程序猿之殇 2008-11-07
  • 打赏
  • 举报
回复

//要获取dir从$_GET里
//要设置起始的dir
extract($_GET);
if($dir == "")
$dir = "...";

if($flag==2) {
$cut1=strrpos($dir,"/");
$dir=trim(substr($dir,0,$cut1));
echo "<SCRIPT LANGUAGE=javascript>";
echo "alert(\"$dir\")";
echo "</SCRIPT>";
}

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧