使用PHP7.2在目录中列出PDF文件
下面的函数列出choosen目录中的所有PDF文件。还可以读取并打印PDF中的歌曲标题(它们都是歌曲)。该脚本在PHP5.6中工作起来很有魅力,但在PHP7.2中却没有。因为我的托管公司,我必须升级到7.2使用PHP7.2在目录中列出PDF文件,php,pdf,file-get-contents,php-7.2,opendir,Php,Pdf,File Get Contents,Php 7.2,Opendir,下面的函数列出choosen目录中的所有PDF文件。还可以读取并打印PDF中的歌曲标题(它们都是歌曲)。该脚本在PHP5.6中工作起来很有魅力,但在PHP7.2中却没有。因为我的托管公司,我必须升级到7.2 function listPDF($dirtoread) { if($handle = opendir("pdf/".$dirtoread)) { //ny $theFiles = array(); $count = 0; while($currentfile = readdir($h
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);
}
}
函数列表PDF($dirtoread){
如果($handle=opendir(“pdf/”$dirtoread)){
//纽约
$theFiles=array();
$count=0;
而($currentfile=readdir($handle)){
如果(!ereg(“^\”,$currentfile)){
$theFiles[$count]=$currentfile;
$count++;
}
}
排序($theFiles,sort\u STRING);
对于($i=0;$i”;
}
closedir($handle);
}
}
对不起!找到了。PHP7中不推荐使用Ereg函数…定义“不工作”。您是否有任何错误?您应该查看负责您的工作的glob
功能