我已经搜索了 stackoverflow 和其他一些网站,并尝试了几个小时的新代码组合,但我放弃了.. 我有 2 个 php 文件,一个名为 getimages.php,另一个名为 mod_slidepluslight.php 我正在使用 Joomla作为 CMS 并使用灯箱制作了幻灯片模块,现在我想通过 .xml 文件中设置的模块参数从 Joomla 内的文件夹中检索图像。我通过使用以下代码做到了这一点:
$imagePath = $params->get('imagePath', 'banners');
现在,当我尝试声明这个变量并在我的代码中使用它时,它什么也没做。
function returnimages($relPath = "/KVD/images/") { 
$dirname = $_SERVER['DOCUMENT_ROOT'] . $relPath . $imagePath; 
$imagePath 应该添加在 /KVD/images/......./ 之后或现在的位置。getimages.php 的整个代码如下所示:
Header("content-type: application/x-javascript");
$imagePath = $params->get('imagePath', 'banners/');
function returnimages($relPath = "/KVD/images/") { 
$dirname = $_SERVER['DOCUMENT_ROOT'] . $relPath . $imagePath; 
$files = array(); 
$curimage = 0; 
if($handle = opendir($dirname)) { 
while(false !== ($file = readdir($handle))){ 
if (preg_match('/\.(jpg|jpeg|gif|png)$/', $file)){ 
print_r ('galleryarray['.$curimage.']="'. $relPath . $file .'";'); 
$curimage++; 
} 
} 
closedir($handle); 
} 
return($files); 
} 
print 'var galleryarray=new Array();'; //Define array in JavaScript 
returnimages() //Output the array elements containing the image file names
谢谢,科恩。