duankun9280 2014-12-02 08:35
浏览 74
已采纳

Filesystem - 文件夹下文件夹下的文件夹...

a busy cat

Hi,

when I click the folder that is in the first folder it just can't recognize what's in it. What is it I'm doing wrong ?

<?php



 $fil = new SplFileObject(__FILE__);


$dato = new DateTime();
$dato->setTimezone(new DateTimeZone('Europe/Copenhagen'));
$dato->setTimestamp($fil->getMTime()); // getMTime sidst modificeret

if($_GET) {
$path = $fil->getPath();
$path = $path . "/" . $_GET['mappe'];
} else {
$path = $fil->getPath();
}


$mappeinterator = new FilesystemIterator($path);

foreach ($mappeinterator as $fileinfo) {

   $type = $fileinfo->isDir();
   if(!$type){


echo '<div style="width: 648px; margin:0 auto;">';
echo '<div id="name">';
echo $fileinfo->getFilename();
echo '</div>';

echo '<div id="kb">';
echo $fileinfo->getSize() . ' kb' . '<br>';
echo '</div>';


echo '<div id="mo">';
echo 'Modified on';
echo '</div>';

echo '<div id="m">';
$modificeret = $dato->format('d-m-Y H:i:s');
echo $modificeret . '<br>';
echo '</div>';

echo '</div><br><br>';

} else {



echo '<div style="width: 648px; margin:0 auto;">';
echo '<div id="name">';


//    ------------------------------------------------------
$m = $fileinfo->getFilename();
echo '<a href=op02.php?mappe=' . $m . '>'; 
echo $m;
echo '</a>';
echo '</div>';
 //    ------------------------------------------------------

echo '<div id="kb">';
echo $fileinfo->getSize() . ' kb' . '<br>';
echo '</div>';


echo '<div id="mo">';
echo 'Modified on';
echo '</div>';

echo '<div id="m">';
$modificeret = $dato->format('d-m-Y H:i:s');
echo $modificeret . '<br>';
echo '</div>';

echo '</div><br><br>';
}

   }


?>

I have more folder in each folder just for the test. But as you can see it does go further

  • 写回答

1条回答 默认 最新

  • dsu89430 2014-12-02 09:09
    关注

    You are using the directory of __FILE__ as base. You have to provide the whole path to your sub-subdir that means including MAPPE. Your directory is not C:\xampp\htdocs\AW\Filsystem\mappe3 but C:\xampp\htdocs\AW\Filsystem\MAPPE\mappe3. Therefore you should include the whole relative path in your link:

    $m = substr($path."\\".$fileinfo->getFilename(), strlen(dirname(__FILE__))+1);
    echo '<a href=op02.php?mappe=' . $m . '>'; 
    

    But beware: using request vars for building a path could be a security problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站