好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何禁止file_get_contents函数读取当前脚本目录外

 <?php $currentdirinfo=pathinfo($_SERVER['SCRIPT_NAME']);//取得当前脚本所在目录信息 $filepath="test/1.txt";//待读取文件路径 $fileinfo=explode('/',$filepath); $filename=$fileinfo[count($fileinfo)-1];//取得待读取文件的文件名,分隔后,为数组中最后一个元素 $targetfile=$_SERVER['DOCUMENT_ROOT'].$currentdirinfo['dirname'].'/'.$filename;//待读取文件名在当前目录的相对路径 if(is_file($targetfile))//判断待读取文件是否在当前脚本所处目录 echo file_get_contents($filename);//如果在,读取文件 else echo '当前目录为:'.$currentdirinfo['dirname'].','.$filepath.'文件不在目录内';//如果不在,提示信息 ?>

查看更多关于如何禁止file_get_contents函数读取当前脚本目录外的详细内容...

  阅读:41次