我正在尝试为joomla中的每个幻灯片图像添加一个链接,但是我一直坚持从没有扩展名的照片中获取文件名。 这是相关的代码:
<?php
$imgrootdir = "templates/".$this->template."/images/";
if ($headerType == "0" || $headerType == "2") {
echo '<img src="'.$imgrootdir.$myimage.'" alt="" />';
} elseif ($headerType == "1" || $headerType == "3") {
$picDir= $imgrootdir.$myfolder;
$picDir .="/";
if (file_exists($picDir) && is_readable($picDir)) {
$folder = opendir($picDir);
} else {
echo '<div class="message">Error! Please check the parameter settings and make sure you have entered a valid image folder path!</div>';
return;
}
$allowed_types = array("jpg","JPG","jpeg","JPEG","gif","GIF","png","PNG","bmp","BMP");
$index = array();
while ($file = readdir ($folder)) {
if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$allowed_types)) {array_push($index,$file);}
}
closedir($folder);
if($display == 'random') {shuffle($index);} else {sort($index);}
foreach ($index as $file) {
$finalpath = $picDir.$file;
// output
echo '<a href="http://testcl.net46.net/index.php/''"><img src="'.$finalpath.'" alt="'.$file.'" /></a>';
}
if ($showControl) echo '<div id="slcontrol"> </div>';
}
?>
答案 0 :(得分:0)
首先,使用Joomla的内置文件处理功能是最佳做法。见http://docs.joomla.org/How_to_use_the_filesystem_package。我认为这些函数内置了错误处理功能。另见JPATH。您可以使用这些函数来删除标记:
$name = JFile::stripExt($filename);
答案 1 :(得分:0)