dpiw16824 2016-10-23 11:52
浏览 48

glob函数无法扫描joomla中的文件夹

I am creating one module for joomla (backend) which must scan given folder for images (which is out of admin directory) and display for each of them input fields. $dir variable gets value of iDirName field from xml files field of joomla module which user types from module edit page.

This file below works only if directory is images and searches for folder within module directory, not root directory of site. Even if I have added in modules image directory another directory(), it does not work, so it can scan /administrator/modules/mod_slide_url_add/images/ this directory but not this /administrator/modules/mod_slide_url_add/images/headers.

I need to be able to scan /images/headers directory from joomla root. Before I used one small form with action to this php file and it worked for fine when I was typing directory like this ../../../images/headers but in this case I was redirected from joomla admin page to clear page with that php file and was getting input fields on a clear page, not on a joomla page. Now I am trying to display that fields directly on joomla page without any redirect. Can you help me?

<?PHP
    $dir = $params->get('iDirName','1');
    echo "Dir=";
    echo $dir;
?>

<table border="0" cellspacing="0" cellpadding="0" align="center">
    <form action="modules/mod_slide_url_add/ValidateWriteLinks.php" autocomplete="off" method="post">
    <?PHP
        if(isset($dir) && $dir!='' && !empty($dir))
        {
            $slcfN=0;
            $sclfTargetDirectory = $dir;
            foreach(glob($sclfTargetDirectory.'*.{jpg,png,gif}',GLOB_BRACE) as $slcfFileName)
            {
                $slcfN++;
                $info = pathinfo($slcfFileName);
                $file_name =  basename($slcfFileName,'.'.$info['extension']);
                $slcfFileName = $sclfTargetDirectory.$file_name.'.txt';
                if(!file_exists($slcfFileName))
                {
                    $FileHandle = fopen($slcfFileName, 'w') or die("can't open file");
                    fclose($FileHandle);
                }
                echo "<tr><td>";
                echo "File No $slcfN -".basename($slcfFileName);
                echo "</td><td>";
                echo "<input type='text' name='URLNo$slcfN' maxlength='105' size='35'>";
                echo "<input type='checkbox' name='ChkBoxNo$slcfN' value='Yes' /> Del File Contents...";
                echo "<input type='hidden' name='FilenameNo$slcfN' value='$slcfFileName'>";
                echo "</td></tr>";
            }
            echo "<tr><td>";
            echo "<input type='hidden' name='slcCounterS' value='$slcfN'>";
            echo "</td><td>";
            echo "<input type='submit' value='E N T E R'>";
            echo "</td></tr>";
        }else{echo"ERROR LVL1";}
    ?>
    </form>
</table>
  • 写回答

1条回答 默认 最新

  • douzhong8856 2016-10-23 17:33
    关注

    I found solution, added to first php code

    $rootpath = JPATH_ROOT;
    

    and then changed this

    $sclfTargetDirectory = $dir;
    

    to this

    $sclfTargetDirectory = $rootpath.$dir;
    

    and module works as I wanted.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算