2

我有一个结构:

  • [目录]
  • [目录名称-1]
    • [data_html]
      • name-1.html - 来自另一个表单的发布值表
      • name-2.html - 来自另一个表单的发布值表
      • name-3.html - 来自另一个表单的发布值表
      • ...
      • name-n.html - 来自另一个表单的发布值表
    • 目录名称-1.html
    • [目录名称 2]
      • 目录名称 2.html
    • [目录名称 3]
      • 目录名称 3.html

索引.php

  1. 我该如何编写catalogue-name-?.html中的函数以将所有data_html -tables的内容合并到catalogue-name- ?. html的一个 html-table 中?

  2. 我该如何编写index.php以将所有catalogue-name-?.html文件列为链接列表?

    • <a href="catalogue-name-1.html">name-1</a>
    • <a href="catalogue-name-2.html">name-2</a>
    • <a href="catalogue-name-3.html">name-3</a>
    • ...
    • <a href="catalogue-name-n.html">名称-n</a>
4

2 回答 2

0

谢谢你的提示。涉及 3 个 PHP 文件: index.php - 有一个条目表单将值发布到work/data.php文件中,然后在其中操作的值保存在相应data_html文件夹中的新 HTML 文件中,然后由work/显示预览.php。在data.php中,有关于此代码:

<?php
// directory names 
$dir_catalogues = '../catalogues/';
$dir_catalogue = $dir_catalogues.$_POST['catalogue_name'];
$dir_html = $dir_catalogue.'/data_html/'; 
$dir_csv = $dir_catalogue.'/data_csv/';

//Check if the directory with the name already exists
//Create our directory if it does not exist
if (!is_dir($dir_catalogues)) {
mkdir($dir_catalogues);
echo "Directory ".$dir_catalogues." created<br>";
}
if (!is_dir($dir_catalogue)) {
mkdir($dir_catalogue);
echo "Directory ".$dir_catalogue." created<br>";
}
if (!is_dir($dir_html)) {
mkdir($dir_html);
echo "Directory ".$dir_html." created<br>";
}
if (!is_dir($dir_csv)) {
mkdir($dir_csv);
echo "Directory ".$dir_csv." created";
}

// file names 
$img_name_html = $_POST['img_name'].'.html';
$img_name_csv = $_POST['img_name'].'.csv';
$catalogue_name = 'catalogue-'.$_POST['catalogue_name'].'.html';

// HTML file content 
$html = '
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Images rights information</title>
    <style>
        ...
    </style>
</head>
<body>
<div class="wrapper">
<table cellpadding="5">
<th colspan="2">Image info</th>
<tr class="thumb_row""><td class="logo" colspan="2"><img class="img_thumb" src="'.$_POST['img_use_url'].'" alt="Thumbnail"><h3>'.$_POST['img_title'].'</h3></td></tr>
<tr><td width="140" class="lab">File name</td><td colspan="5">'.$_POST['img_name'].'</td></tr>
<tr><td width="140" class="lab">Description</td><td colspan="5">'.$_POST['img_description'].'</td></tr>
<tr><td width="140" class="lab">Source URL</td><td colspan="5"><a href="'.$_POST['img_source_url'].'" target="_blank">'.$_POST['img_source_url'].'</a></td></tr>
<tr><td width="140" class="lab">Image use URL</td><td colspan="5"><a href="'.$_POST['img_use_url'].'" target="_blank">'.$_POST['img_use_url'].'</a></td></tr>
<tr><td width="140" class="lab">Copyright owner</td><td colspan="5">'.$_POST['img_copyright_owner'].'</td></tr>
<tr><td width="140" class="lab">Author</td><td colspan="5">'.$_POST['img_author'].'</td></tr>
<tr><td width="140" class="lab">Author\'s URL</td><td colspan="5"><a href="'.$_POST['img_author_url'].'" target="_blank">'.$_POST['img_author_url'].'</a></td></tr>
<tr><td width="140" class="lab">License</td><td colspan="5">'.$_POST['img_license'].'</td></tr>
<tr><td width="140" class="lab">License Nr.</td><td colspan="5">'.$_POST['img_license_nr'].'</td></tr>
</table>
</div>
</body>
</html>';
......
// create catalogue HTML file
    file_put_contents($dir_catalogue .'/'.$catalogue_name, $html, FILE_APPEND | LOCK_EX);
于 2019-11-30T18:02:49.553 回答
0

我取得了一些进展(找到并应用了 som 工作脚本)。但我坚持以下几点:到目前为止,我的代码中有关于这个:

<!-- FILE HEADDINGS -->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Images rights information</title>
	<style>
		*{font-family: arial, tahoma, verdana;}
		.wrapper{width: 900px; margin:auto;box-sizing:border-box;}
		table{width:100%}
		th{font-size:2.2em; font-weight:bold;}
		.thumb_row{background:#eee;}
		td.logo, th{border-bottom:2px solid #999;}
		.img_thumb{max_height: 180px; width:auto; margin: .2em; float:left;}
		td.logo img{ float: left; margin-right:2em;}
		td a img{border: 2px solid blue;}
		td a:hover img{border: 2px solid orange;}
		td.lab{font-weight:bold;vertical-align:top;}
		td h3{font-size:2em; font-weight:bold}
	</style>
</head>
<body>
<div class="wrapper">
<!-- FILE HEADDINGS END -->
<table cellpadding="5">
<th colspan="2">Image info</th>
<tr class="thumb_row"><td class="logo" colspan="2"><img class="img_thumb" src="'.$_POST['img_use_url'].'" alt="Thumbnail"><h3>'.$_POST['img_title'].'</h3></td></tr>
<tr><td width="140" class="lab">File name</td><td colspan="5">'.$_POST['img_name'].'</td></tr>
<tr><td width="140" class="lab">Description</td><td colspan="5">'.$_POST['img_description'].'</td></tr>
<tr><td width="140" class="lab">Source URL</td><td colspan="5"><a href="'.$_POST['img_source_url'].'" target="_blank">'.$_POST['img_source_url'].'</a></td></tr>
<tr><td width="140" class="lab">Image use URL</td><td colspan="5"><a href="'.$_POST['img_use_url'].'" target="_blank">'.$_POST['img_use_url'].'</a></td></tr>
<tr><td width="140" class="lab">Copyright owner</td><td colspan="5">'.$_POST['img_copyright_owner'].'</td></tr>
<tr><td width="140" class="lab">Author</td><td colspan="5">'.$_POST['img_author'].'</td></tr>
<tr><td width="140" class="lab">Author\'s URL</td><td colspan="5"><a href="'.$_POST['img_author_url'].'" target="_blank">'.$_POST['img_author_url'].'</a></td></tr>
<tr><td width="140" class="lab">License</td><td colspan="5">'.$_POST['img_license'].'</td></tr>
<tr><td width="140" class="lab">License Nr.</td><td colspan="5">'.$_POST['img_license_nr'].'</td></tr>
</table>
<!-- FILE FOOTER -->
</div>
</body>
</html>

// CSV file content

$csv = $_POST['catalogue_name'].'|'.$_POST['img_title'].'|'.$_POST['img_name'].'|'.$_POST['img_description'].'|'.$_POST['img_source_url'].'|'.$_POST['img_copyright_owner'].'|'.$_POST['img_author'].'|'.$_POST['img_author_url'].'|'.$_POST['img_license'].'|'.$_POST['img_license_nr'];

// create catalogue HTML file
	file_put_contents($dir_catalogue .'/'.$catalogue_name.'.html', $html, FILE_APPEND | LOCK_EX);
	file_put_contents($dir_catalogue .'/index.html', $html, FILE_APPEND | LOCK_EX);
// create catalogue CSV file
	file_put_contents($dir_catalogue .'/'.$catalogue_name.'.csv', $csv, FILE_APPEND | LOCK_EX);
	file_put_contents($dir_catalogue .'/index.csv', $csv, FILE_APPEND | LOCK_EX);
}

但结果是将整个 $html 代码插入到目录文件中(我希望只在开头添加“标题”,所有单独保存的表格,以及“页脚”也总是只在 HTML 的末尾-catalog 文件。CSV 输出将所有变量放入一行中。我希望将每条记录放在一行中。

于 2019-12-01T22:16:26.190 回答