2013-06-08 4 views
0

PHP 버전 5.4.16을 실행하는 서버가 있고 디렉토리 내의 파일을 나열하기 위해 scandir을 사용하려고합니다. 문제가 무엇인지 파악하는 데 어려움을 겪고 있습니다. 나는 ../store/dir_to_scan과/root/store/dir_to_scan을 시도했다. 나는 또한 glob과 scandir를 모두 사용하여 아래 둘 모두를 사용할 수 없으므로 시도했다. dir_to_scan 디렉토리를 지우면/root/store 디렉토리가 열거됩니다.이 디렉토리는 내가 가장 혼란스러운 것을 발견합니다. 나는 chmod'd 폴더와 파일을 사용 권한 문제가 아닌지 확인하기 위해 777 번으로도 사용했습니다. foreach() [file] => /root/html/test.php [line] => 5)에 대해 제공된 잘못된 인수가 "Array ([type] => 2 [message] => 올바른 디렉토리 설정.php scandir() - foreach() [file]에 잘못된 인수가 제공되었습니다.

도움 주셔서 감사합니다.

디렉토리 설정

/root/html //where php script is run 
/root/store/dir_to_scan //files I need to list 

PHP 스크립트

<? 
#$files = glob('../store/dir_to_scan/*', GLOB_BRACE); 
$files = scandir("/root/store/dir_to_scan/"); 
    foreach($files as $file) { 

     //do work here 
     if ($file === '.' || $file === '..') { 
       continue; 
     } 
    echo $file . "<br>"; 
} 
print_r(error_get_last()); 
?> 

답변

0

이 바보 만의 끝에 후행 슬래시를 공급하려고 할 수 있습니다

/루트/저장/dir_to_scan ->

이해야
$files = scandir("/root/store/dir_to_scan/"); 
+0

해결합니다. :/ – user1628514

0

내가 불행하게도 같은 문제가 또는 후행 슬래시없이 존재, 당신의 응답을 주셔서 감사 문제

$carpeta= "/root/store/dir_to_scan"; 
    if(is_dir($carpeta)){ 
     if($dir = opendir($carpeta)){ 
      while(($file = readdir($dir)) !== false){ 
       if($file != '.' && $file != '..' && $file != '.htaccess'){ 
        echo $file; //or save file name in an array.. 
       // $array_file[] = $file; 

       } 
      } 
      closedir($dir); 
     } 
    } 
+0

스페인어로 된 이유는 무엇입니까? –

+0

은 내가이 문제에 사용하는 것과 동일한 코드이며, 스페인어 국가에 살고 있습니다. $ carpeta 만 스페인어 단어입니다. – kraysak

+0

글쎄요, 성공에 조금 더 가까워졌습니다. 다른 스크립트와 마찬가지로/root/store를 읽을 수 있지만/root/store/dir_to_scan에 파일을 나열하지 않습니다. 그것은 더 이상 "array ([type] => 2 [message] => 잘못된 인수 for foreach() [file] => /root/html/test.php [line] => 5)"오류를 발생시킵니다. . – user1628514