2013-06-06 2 views
0

저는 PHP 스크립트로 특정 파일을위한 디렉토리를 읽고 각각에 대해 스크립트를 실행하려고했지만 작동시키지 못했습니다. 계속 오류가 발생하여 디렉토리를 열지 못했습니다. 내가 만든 작은 실수가 있는지 궁금 해서요. 왜 파일을 읽지 않는지 알아 내려고 애 쓰고 있습니다.디렉토리에서 PHP 스크립트로 파일을 읽으려고 시도합니다.

<?php 
$bg = "bg-body.png"; 
?> 

<html> 
<style type="text/css"> 
body { 
background-image: url('<?php echo $bg;?>'); 
background-repeat: repeat; 
background-position: top center; 
} 
</style> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Movie List</title> 
</html> 


<?php 

$file_list = array(); 
$file_folder = "C:\Users\Looper\Documents"; 

//use the directory class 
$files = dir($file_folder); 

//read all files from the directory 
while ($file = $files->read()) { 
    chdir($file_folder); 
    $files = glob('*.mov'); 
    foreach ($files as $file) { 
    $file_list[] = $file; 
    } 
} 
closedir($files->handle); 

//display image 
foreach($file_list as $file) { 
    $theData = file_get_contents($file) or die("Unable to retrieve file data"); 
} 

$months = ['January' => '_01', 'February' => '_02', 'March' => '_03', 'April' => '_04', 'May' => '_05', 'June' => '_06', 'July' => '_07', 'August' => '_08', 'September' => '_09', 'October' => '_10', 'November' => '_11', 'December' => '_12']; 
foreach($months as $key => $month){ 
    if(strpos($file,$month)!==false){ 
     echo "<div style ='text-align: center; text-shadow: 0 .8px 0 #c4bc2a; margin-top: 30px; margin-bottom: 20px; font:16px verdana,tahoma,sans-serif; 
       color:#6b8942; font-weight:bold; text-decoration: underline;'>Movie List for $key 2013</div>"; 
    } 
} 


$string = $theData; 
$titles = explode("\n", $string); 

function getInfo($string){ 
    $Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX']; 
    $split = preg_split("/\"(.+)\"/", $string, 0, PREG_SPLIT_DELIM_CAPTURE); 
    if(count($split) == 3){ 
     preg_match("/(".implode("|", $Ratings).")\s/", $split[0], $matches); 
     $rating = $matches[0]; 
     return ["title" => $split[1], "rating" => $rating]; 
    } 
    return false; 
} 


$infolist = array(); 
foreach($titles as $title){ 
    $info = getInfo($title); 
    if($info !== false){ 
    $infolist[] = $info; 
    } 
} 

usort($infolist, "infosort"); 

function infosort($lhs,$rhs) { 
    return strcmp($lhs['rating'], $rhs['rating']); 
} 

foreach ($infolist as $info) { 
     echo "<div style ='margin-bottom: 3px; text-align: center; 
      font:13px Verdana,tahoma,sans-serif;color:green;'> 
      {$info["title"]} : {$info["rating"]}</div>"; 
} 

echo "<div style='text-align:center; margin-top: 20px;'><img src='shclogo.png' 
alt='Logo' width='200' height='133'/></div>"; 

?> 

답변

0

"C:\Users\Looper\Documents"은 유효한 경로가 아닙니다. "C:\\Users\\Looper\\Documents" 일 수 있습니다 ..

관련 문제