Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用目录/文件夹内容填充HTML表_Php_Html_Html Table_Directory - Fatal编程技术网

Php 用目录/文件夹内容填充HTML表

Php 用目录/文件夹内容填充HTML表,php,html,html-table,directory,Php,Html,Html Table,Directory,在网站HTML表中,我需要用位于网站特定目录中的PDF文件的名称填充该表 例如: 表左侧年份:2010年、2011年、2012年 表格顶部月份:1月、2月、3月 数据记录需要从站点根目录的结构化文件夹设置中提取: html\u公共/上传文件/文件类型\u a/2010/01jan html\u公共/上传文件/文件类型\u a/2010/02 html\u公共/上传文件/文件类型\u a/2010/03mar 因此,上载到/01jan文件夹中的PDF文档将在HTML表的相应单元格中显示该PDF文件

在网站HTML表中,我需要用位于网站特定目录中的PDF文件的名称填充该表

例如:

表左侧年份:2010年、2011年、2012年
表格顶部月份:1月、2月、3月

数据记录需要从站点根目录的结构化文件夹设置中提取:

html\u公共/上传文件/文件类型\u a/2010/01jan html\u公共/上传文件/文件类型\u a/2010/02 html\u公共/上传文件/文件类型\u a/2010/03mar


因此,上载到/01jan文件夹中的PDF文档将在HTML表的相应单元格中显示该PDF文件的名称。

此PHP代码将遍历您指定的目录,并将找到的所有PDF文件放入名为
$files
的数组中。您可能需要调整
$dir

$dir = 'html_public/uploadedfiles/files_type_a/2010/'; //directory to pull from
$skip = array('.','..'); //a few directories to ignore

$dp = opendir($dir); //open a connection to the directory
$files = array();

if ($dp) {
    while ($file = readdir($dp)) {
        if (in_array($file, $skip)) continue;

        if (is_dir("$dir$file")) {
            $innerdp = opendir("$dir$file");

            if ($innerdp) {
                while ($innerfile = readdir($innerdp)) {
                    if (in_array($innerfile, $skip)) continue;

                    $arr = explode('.', $innerfile);
                    if (strtolower($arr[count($arr) - 1]) == 'pdf') {
                        $files[$file][] = $innerfile;
                    }
                }
            }
        }
    }
}
此部分将生成一个HTML表格并显示所有适用的文件:

<table>
    <? foreach ($files as $directory => $inner_files) { ?>
    <tr>
        <td>Folder: <?= $directory ?></td>
    </tr>

        <? foreach ($inner_files as $file) { ?>
        <tr>
            <td>File: <?= $directory ?>/<?= $file ?></td>
        </tr>
        <? } ?>
    <? } ?>
</table>

文件夹:
文件:/

需要更多信息。什么样的环境?PHP之类的?