简体   繁体   English

在Joomla 2.5中获取文件目录列表的绝对PHP URL

[英]Getting an absolute PHP URL for a file directory listing in Joomla 2.5

I'm trying to use a PHP script in conjunction with Flexslider in Joomla 2.5 to be able to autoload slideshows and thumbnail slider nav from a folder without having to code it out for each slideshow, as described in part here . 我想结合使用PHP脚本Flexslider中的Joomla 2.5到能够从一个文件夹自动加载幻灯片和缩略图滑块导航,而不必如部分所述,它的代码对每个幻灯片这里

I have tried to implement several different methods both Joomla specific and just to PHP, but I sense I am not incorporating them correctly. 我尝试实现Joomla特有的和PHP的几种不同方法,但是我感觉我没有正确地合并它们。

1)
    $path = JPATH_COMPONENT; 

2)
    $path = JURI::root();

3)
    $path = $_SERVER['DOCUMENT_ROOT'];
4)
    <?php
    define('ROOT_DIR', dirname(__FILE__));
    define('ROOT_URL', substr($_SERVER['PHP_SELF'], 0, - (strlen($_SERVER['SCRIPT_FILENAME']) - strlen(ROOT_DIR))));
    ?> 

If anyone can show me how to make any of these or another method play nice with: 如果有人可以告诉我如何使这些方法或其他方法更有效地使用:

$imgdir = 'flex/demo/images/'; //Pick your folder

So that one of Joomla's pretend urls for sub-menu items doesn't look for it in a directory that doesn't exist, that would be just too great. 因此,Joomla伪装的子菜单项URL之一不会在不存在的目录中查找,这实在太大了。

As shown in the linked article, the whole script I'm using is stuck in via Jumi as thus: 如链接文章中所示,我正在使用的整个脚本通过Jumi插入,如下所示:

<link rel="stylesheet" href="flex/flexslider.css" type="text/css" media="screen" /> 

 <!-- jQuery -->
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.min.js">\x3C/script>')</script>

  <!-- FlexSlider -->
  <script defer src="flex/jquery.flexslider.js"></script>

<div id="slider" class="flexslider">
<?php
$imgdir = 'flex/demo/images/'; //Pick your folder
$allowed_types = array('jpg','jpeg','gif'); //Allowed types of files
$dimg = opendir($imgdir);//Open directory
while($imgfile = readdir($dimg))
{
  if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
      in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
/*If the file is an image add it to the array*/
  {$a_img[] = $imgfile;}
}
echo "<ul class=\"slides\" >";

 $totimg = count($a_img);  //The total count of all the images
//Echo out the images and their paths incased in an li.
 for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";

     echo "</div>";
       echo "<div id=\"carousel\" class=\"flexslider\">";

echo "<ul class=\"slides\" >";

 $totimg = count($a_img);  //The total count of all the images
//Echo out the images and their paths incased in an li.
 for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";
?>
        </div>

<script>
 $(window).load(function(){
      $('#carousel').flexslider({
        animation: "slide",
        controlNav: false,
        animationLoop: true,
        slideshow: false,
        itemWidth: 210,
        itemMargin: 5,
        asNavFor: '#slider'
      });

      $('#slider').flexslider({
        animation: "slide",
        controlNav: false,
        animationLoop: true,
        slideshow: true,
        sync: "#carousel",
        start: function(slider){
          $('body').removeClass('loading');
        }
      });
    });
  </script>

UPDATE - RESOLVED UPDATE - 已解决

I initially mis-worded my question, I was having trouble getting the correct URL, not path for the images. 最初,我用错词表达了我的问题,我无法获取正确的URL,而不是图像的路径。 At some point it was adding in a Joomla generated directory between my desired directory for the images and the images path. 在某个时候,它在我所需的图像目录和图像路径之间添加了一个Joomla生成的目录。 For some reason either I didn't interpret that correctly or it seems to have gone away by itself. 由于某种原因,或者我没有正确解释它,或者它似乎已经消失了。

I needed to add a leading '/' but it wouldn't let me add it into the line: 我需要添加一个前导“ /”,但不允许我将其添加到该行中:

$imgdir = 'flex/demo/images/'; //Pick your folder

So I addressed my problem by changing this: 因此,我通过更改以下内容解决了我的问题:

//Echo out the images and their paths incased in an li.
 for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";

to: 至:

//Echo out the images and their paths incased in an li.
 for($x=0; $x < $totimg; $x++){echo "<li><img src='/" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";

in the two instances it occurs in the code for outputting the url to the img src. 在这两种情况下,它出现在将URL输出到img src的代码中。

Hope this helps someone else! 希望这对别人有帮助!

Please use JUri:base() to get the base URI of your Joomla site. 请使用JUri:base()获取Joomla网站的基本URI

<link rel="stylesheet" href="<?php echo JUri:base(); ?>flex/flexslider.css" type="text/css" media="screen" /> 

Change 更改

$imgdir = 'flex/demo/images/'; //Pick your folder

to

$imgdir = JPATH_ROOT.'/flex/demo/images/'; //Pick your folder

These constants are defined for use in Joomla and extensions: Constants 定义了这些常量供在Joomla和扩展程序中使用: 常量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM