我一直在尝试让我的 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>";
?>