2016-09-18 3 views
-2

폴더의 목록 파일을 목록에 넣고 싶습니다. 목록은 각 3 개의 파일을 분할해야합니다. 목록은 Materialize, 의 카드가 될 것이므로 왜 내가 각각 3 개의 파일을 새로운 행으로 시작하고 싶은지에 대한 것입니다. 어떻게하면 좋을까요? 누군가 나를 도울 수 있습니까? 감사합니다 :)PHP로 파일 나열 및 새 행 시작

+0

을 살펴 보겠습니다 PHP5.6 + 으로 DirectoryIterator를 사용해야합니까? – webNeat

+0

'if ($ counter == 3) {echo 'somethig'; }' –

답변

0
 <?php 
      $myDirectory = opendir("./downloads"); 
      while($entryName = readdir($myDirectory)) { 
       $dirArray[] = $entryName; 
      } 
      closedir($myDirectory); 
      // count elements in array 
      $indexCount = count($dirArray); 
      // sort 'em 
      sort($dirArray); 

      // loop through the array of files and print them all 
      for($index=0; $index < $indexCount; $index++) { 
       if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files 


        print('<li class="collection-item dismissable"><div>'.$dirArray[$index].'<a href="https://DOMAIN.xyz/downloads/'.$dirArray[$index].'" class="secondary-content"><i class="material-icons">send</i></a></div></li>'); 
       } 
      } 
     ?> 
0

당신은 그 당신이 시도 코드를 표시 할 수 있습니다, 안녕하세요 다음

$dir = "somepath"; 
$files = Array(Array(), Array(), Array()); // This should set up 3 nested arrays 
$ind = 0; 

foreach(new DirectoryIterator($dir) as $fileInfo) { 
    if ($fileInfo->isDot()) continue; 
    if ($ind >= 3) $ind = 0; 
    array_push($files[$ind], $fileInfo->getFileName()); 
    $ind++; 
} 
+0

오류가 있습니다. –

+0

구문상의 설탕을 잊어 버렸습니다. 이제 작동하고, 재미있게 지내십시오. – Fohlen