为了账号安全,请及时绑定邮箱和手机立即绑定

$act和$filename没定义成功,提示Notice: Undefined index:

require_once 'dir.func.php';

require_once 'file.func.php';

require_once 'common.func.php';

$path="file";

$info=readDirectory($path);

$act= $_REQUEST['act'];

$filename=$_REQUEST['filename'];

if($act == "createFile"){

//创建文件

echo $_REQUEST['act'],"--";

echo $_REQUEST['filename'];

// $mes=createFile($path."/".$filename);

// alertMes($mes,$redirect);

}

?>


浏览器上显示

Notice: Undefined index: act in D:\WWW\fileManager\index.php on line 8
Notice: Undefined index: filename in D:\WWW\fileManager\index.php on line 9

$act和$filename没定义成功,这个是什么原因呀!有同学说 $_REQUEST前面加@就没有提示了,但是我创建不了文件呀。。


正在回答

8 回答

重命名只获取到了重命名时的名字,没有获取到原来的filename

0 回复 有任何疑惑可以回复我~

Notice: Undefined index: act in D:\phpStudy\WWW\dongtai\everyany\shopimooc\admin\doAdminAction.php on line 4

Notice: Undefined variable: mes in D:\phpStudy\WWW\dongtai\everyany\shopimooc\admin\doAdminAction.php on line 22

0 回复 有任何疑惑可以回复我~

还是不行,求解!!!<?php
header("Content-Type: text/html;charset=utf-8");
require_once 'dir.func.php';
require_once 'file.func.php';
require_once 'common.func.php';
$path = 'File';
$act = $_REQUEST['act'];
$filename = $_REQUEST['filename'];
$info = readDirectory($path);
$redirect = "index.php?path={$path}";
if ($act == "createFile") {
   //创建文件
   //echo $filename;
   //echo $path."--";
   $mes = createFile($path . "/" . $filename);
   alterMes($mes, $redirect);
} elseif ($act == "showContent") {
   $content = file_get_contents($filename);
   //echo "<textarea readonly='readonly' cols='100' rows='10'>{$content}</textarea>";
   if (strlen($content)) {
       highlight_string($content);  //高亮显示字符串中的PHP代码
       // 高亮显示文件中的PHP代码  highlight_file($content)
   } else {
       alterMes("文件没有内容,请编辑后再查看!", $redirect);
   }
} elseif ($act == "editContent") {
   //修改文件内容
   //获取文件内容
   $content = file_get_contents($filename);
   $str = <<< EOF
    <form action = 'index.php?act = doEdit' method = 'post'>
    <textarea name = 'content' cols ='100' rows = '20'>{$content}</textarea></br>
    <input type='hidden' name='filename' value='{$filename}'/>
    <input type="hidden" name="path" value="{$path}" />
    <input type = 'submit' value = "修改文件内容"/>
    </form>
EOF;
   echo $str;
} elseif ($act == "doEdit") {
   //修改文件内容的操作
   $content = $_REQUEST('content');
   //echo $filename;exit;
   echo $content;
   if (file_put_contents($filename, $content)) {
       $mes = "文件修改成功";
   } else {
       $mes = "文件修改失败";
   }
   alterMes($mes, $redirect);
} elseif ($act == "renameFile") {
   //完成重命名
   $str = <<<EOF
<form action="index.php?act=doRename" method ="post">
请填写新文件名:<input type="text" name="newname" placeholder="重命名"/>
<input type='hidden' name='filename' value='{$filename}'/>
<input type="submit" value="重命名"/>
</form>
EOF;
   echo $str;
}elseif($act == "deRename"){
   //实现重命名的操作
   $newname = $_REQUEST['newname'];
   renameFile($filename,$newname);
}

?>

0 回复 有任何疑惑可以回复我~

我是小白,应该是表单那里没有  name="filename" name="path"这两个

0 回复 有任何疑惑可以回复我~

因为index.php在打开的的时候就会去执行代码,显然这两个变量在未添加新文件的时候,是不存在的,所以分别做一个判断就可以了,代码如下【请看加粗部分】:

<?php
require_once 'dir.func.php';
require_once 'file.func.php';
require_once 'common.func.php';
$path="file";
$info=readDirectory($path);
// print_r($info);

if(isset($_REQUEST['act'])){
    $act=$_REQUEST['act'];
}
if(isset($_REQUEST['filename'])){
    $filename=$_REQUEST['filename'];
}
$redirect="index.php?path={$path}";
if(isset($act)){
    if($act == "createFile"){
        $mes = createFile($path."/".$filename);
        alertMes($mes,$redirect);
    }
}

5 回复 有任何疑惑可以回复我~

我也出现这样的情况,现在还不不知道怎么办。顶上去~

0 回复 有任何疑惑可以回复我~

这个比较简单,你可以@压制,或者重定义一下这些post,get或者request请求

1 回复 有任何疑惑可以回复我~
#1

治贤 提问者

怎么重新定义?能说简单点吗!?我现在用@压制也没有用的,因为我发现echo输出不了任何东西。。
2015-05-30 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

$act和$filename没定义成功,提示Notice: Undefined index:

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信