我想添加一个链接到joomla中的每个幻灯片图片,但我一直在从没有扩展名的照片中获取文件名。 这是相关代码:在没有扩展名的情况下获取文件名在php
<?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>';
}
?>
我试过你说的话,但不是不带扩展名的文件名,有没有索引扩展。请帮忙。我目前的代码是:''//输出 $ name = JFile :: stripExt($ filename); echo'
'; } if($ showControl)echo'
'; } ?>' – mwenta我假设您的href =“testcl.net46.net/index.php /..name名称最后有实际的文件名,即mypic.jpg请注意”/ index。 php /“不是一个文件夹,它是一个文件本身,如果你的mypic.jpg位于你网站的根目录下,请尝试href =”testcl.net46.net/$name“ – skibulk
也不行。每个图像都有链接http://testcl.net46.net/index和404s。到我的网页的链接是http://testcl.net46.net/index.php/link,这就是为什么我把index.php放在之前。 $ name ..请问我应该把代码放在哪里?我的确做错了。 – mwenta