2011-11-26 3 views
0

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>'; 
} 
?> 

답변

0

그럼 먼저 줌라의 내장에서 파일 처리 기능을 사용하는 것이 가장 좋은 방법은 다음과 같습니다 이는 관련 코드입니다. http://docs.joomla.org/How_to_use_the_filesystem_package을 참조하십시오. 함수는 오류 처리 기능이 내장되어 있다고 생각합니다. 또한 JPATH를 참조하십시오. 당신은 너무로 태그를 제거하기 위해이 기능을 사용할 수 있습니다

$name = JFile::stripExt($filename); 
+0

당신이 말했지만, 대신 확장자를 제외한 파일 이름, 확장자없이 인덱스를가했습니다. 도와주세요. 현재 코드는 다음과 같습니다 :'// output $ name = JFile :: stripExt ($ filename); echo ''.$file.''; } if ($ showControl) echo '

'; } ?> – mwenta

+0

href = "testcl.net46.net/index.php/"..$ 이름 끝에 실제 파일 이름이있는 것으로 가정합니다. 예 : mypic.jpg. "/ index. php/"는 폴더가 아니며 파일 자체입니다 mypic.jpg가 사이트의 루트 디렉토리에 있다면 href ="testcl.net46.net/$name " – skibulk

+0

시도해도됩니다. 모든 이미지는 http://testcl.net46.net/index와 404s 링크를 가지고 있습니다. 내 페이지에 대한 링크는 http://testcl.net46.net/index.php/link입니다. 그래서 index.php를 앞에 두었습니다. $ name .. 내가 코드를 넣어야하는 위치를 알려주시겠습니까? – mwenta

관련 문제