【问题标题】:Listing PDF files in dir with PHP 7.2使用 PHP 7.2 在 dir 中列出 PDF 文件
【发布时间】: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


【解决方案1】:

对不起!找到了。 php 7 中不推荐使用 Ereg 函数...

【讨论】:

  • 你应该看看为你工作的glob函数
猜你喜欢
  • 2018-01-27
  • 1970-01-01
  • 2011-04-21
  • 1970-01-01
  • 2019-03-29
  • 2019-07-07
  • 2018-08-25
  • 1970-01-01
相关资源
最近更新 更多