【发布时间】:2019-04-11 00:53:36
【问题描述】:
下面的函数列出了所选目录中的所有 PDF 文件。还可以读取并打印出 PDF 中的歌曲名称(它们都是歌曲)。该脚本在 PHP 5.6 中就像一个魅力,但在 PHP 7.2 中则不然。由于我的托管公司,我必须升级到 7.2。
function listPDF($dirtoread) {
if($handle = opendir("pdf/".$dirtoread)) {
//ny
$theFiles = array();
$count = 0;
while($currentfile = readdir($handle)) {
if(!ereg('^\.',$currentfile)) {
$theFiles[$count] = $currentfile;
$count++;
}
}
sort($theFiles,SORT_STRING);
for ($i=0; $i < count($theFiles); $i++){
$string = file_get_contents("pdf/".$dirtoread."/".$theFiles[$i]);
$start = strpos($string, "<dc:title>") + 10;
$length = strpos(substr($string, $start), '</dc:title>');
if ($length) {
$title = strip_tags(substr($string, $start, $length));
}
echo "<a class='popup gallery pdf' rel='width:700;height:600' href='pdf/".$dirtoread."/".$theFiles[$i]."' style='text-decoration:none; line-height:2em;'><img src='pdf/pdf_small.gif' align='bottom' border='0'> ".$title."</a><br>";
}
closedir($handle);
}
}
【问题讨论】:
-
定义“不工作”。你有什么错误吗?
标签: php pdf file-get-contents php-7.2 opendir