簡體   English   中英

在Joomla 2.5中獲取文件目錄列表的絕對PHP URL

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

我想結合使用PHP腳本Flexslider中的Joomla 2.5到能夠從一個文件夾自動加載幻燈片和縮略圖滑塊導航,而不必如部分所述,它的代碼對每個幻燈片這里

我嘗試實現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))));
    ?> 

如果有人可以告訴我如何使這些方法或其他方法更有效地使用:

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

因此,Joomla偽裝的子菜單項URL之一不會在不存在的目錄中查找,這實在太大了。

如鏈接文章中所示,我正在使用的整個腳本通過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 - 已解決

最初,我用錯詞表達了我的問題,我無法獲取正確的URL,而不是圖像的路徑。 在某個時候,它在我所需的圖像目錄和圖像路徑之間添加了一個Joomla生成的目錄。 由於某種原因,或者我沒有正確解釋它,或者它似乎已經消失了。

我需要添加一個前導“ /”,但不允許我將其添加到該行中:

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

因此,我通過更改以下內容解決了我的問題:

//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 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>";

在這兩種情況下,它出現在將URL輸出到img src的代碼中。

希望這對別人有幫助!

請使用JUri:base()獲取Joomla網站的基本URI

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

更改

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

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

定義了這些常量供在Joomla和擴展程序中使用: 常量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM