2013-03-18 2 views
-1

현재 사용자가 특정 파일에 일부 문서를 업로드 할 수있는 사이트의 업로드 시스템이 있습니다. 나중에이 문서를 다운로드 할 수 있도록해야합니다. 특정 디렉토리의 모든 파일을 반복하고 파일에 대한 다운로드 링크를 만드는 쉬운 방법이 있습니까? 같은특정 폴더의 모든 파일에서 다운로드 링크 만들기

뭔가 : 사전에

foreach($file){ 
    echo '<a href=""'somepath/'.$file.'">somefilename</a>'; 
} 

많은 감사합니다.

+0

왜 downvote? – AnchovyLegend

답변

1
if($dh = opendir('path/to/directory')) { 
    while(($file = readdir($dh)) !== false) { 
     if($file == "." || $file == "..") { continue; } 
     echo '<a href="path/to/directory/' . $file . '">' . $file . '</a>'; 
    } 
    closedir($dh); 
} 
+0

+1, 정확히 내가 원했던 것, 아주 많이, 분명하고 유용한 예제를 감사드립니다! – AnchovyLegend

0

opendir이 표시됩니다.

질문에 적응 해당 페이지에서 예 :

$dir = "/etc/php5/"; 

$path = "/webpath"; 

// Open a known directory, and proceed to read its contents 
if (is_dir($dir)) { 
    if ($dh = opendir($dir)) { 
     while (($file = readdir($dh)) !== false) { 
      echo "<a href=\"$webpath/$file\">$file</a>"; 
     } 
     closedir($dh); 
    } 
} 
관련 문제