Php 从图像目录创建多个HTML文件
我有一个技术插图,我需要地图面积形成一个在线手册大机构。我已经制作了一个基本引擎,用于将每个文件链接在一起并向前和向后导航。但是由于大量的图像,我想创建一组基本的HTML文件,然后我可以浏览并编辑相关部分 我想要的是搜索目录(images/schematic/)并为每个图像创建一个HTML文件(imagefilename.png)。该文件将使用图像的名称(imagefilename)。html文件的主体类似于以下内容Php 从图像目录创建多个HTML文件,php,Php,我有一个技术插图,我需要地图面积形成一个在线手册大机构。我已经制作了一个基本引擎,用于将每个文件链接在一起并向前和向后导航。但是由于大量的图像,我想创建一组基本的HTML文件,然后我可以浏览并编辑相关部分 我想要的是搜索目录(images/schematic/)并为每个图像创建一个HTML文件(imagefilename.png)。该文件将使用图像的名称(imagefilename)。html文件的主体类似于以下内容 $html=' <!DOCTYPE html PU
$html='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$imageFileName.'</title>
</head>
<body>
<div id="image-holder">
<div class="img-title">changeMeLater</div>
<img src="'.$imageDir .$FullImageFileName.'" width="640" height="751" alt="'.$imageFileName.'-diagram" usemap="#mapFor-'.$imageFileName.'">
<map name="'.$imageFileName.'-imageMap" id="mapFor-'.$imageFileName.'">
</map>
</div>
<div id="partsDescription-tabContent" class="content"></div>
<div id="instructions-tabContent" class="content"></div>
<div id="notes-tabContent" class="content"></div>
<div id="stockControl-tabContent" class="content"></div>
</body>
</html> ';
$html='1!'
提供的代码为您提供了文件名。你只需要换一条线
echo basename($files[$i])."<br/>\n";
echo basename($files[$i])。“
\n”;
用这样的东西代替它
echo "<img src='/images/schematic/" . basename($files[$i]) . "'></img><br />\n";
echo“
\n”;
然后将图像一个接一个地输出。提供的代码给出了文件名。你只需要换一条线
echo basename($files[$i])."<br/>\n";
echo basename($files[$i])。“
\n”;
用这样的东西代替它
echo "<img src='/images/schematic/" . basename($files[$i]) . "'></img><br />\n";
echo“
\n”;
这将一个接一个地输出您的图像。好的,我想我在这里成功地实现了这一切。无论出于何种原因,任何人都可以尝试做类似的事情,欢迎任何进一步的建议或改进
<?php
$dir = opendir ("./images"); //the image directory to read
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.png',1)) {
$fileTitle= basename($file, ".png");
$imageSrc= "./images/schematic/".$file;
$html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$fileTitle.'</title>
</head>
<body>
<div id="image-holder">
<div class="img-title">'.$fileTitle.'</div>
<img src=".'.$imageSrc.'" width="640" height="751" style="border: none;" alt="'.$fileTitle.'-diagram" usemap="#mapFor-'.$fileTitle.'">
<map name="'.$fileTitle.'-imageMap" id="mapFor-'.$fileTitle.'">
<!-------------------------------- '.$fileTitle.' Mapping ------------------------------------->
</map>
</div>
<div id="partsDescription-tabContent" class="content"></div>
<div id="instructions-tabContent" class="content"></div>
<div id="notes-tabContent" class="content"></div>
<div id="stockControl-tabContent" class="content"></div>
</body>
</html>';
$url= './DirectoryForHTMLfiles/'.$fileTitle.'.html';
$f=@fopen($url,"r"); //check to see if file already exists, if it does then close
if($f)
{
fclose($f);
$stat= ' existing'; // this is for the list of files displayed in your browser window simply displaying file exists
}
else {
$myfile = fopen ($url, 'w') or die("Can not open file"); // else if file does not exist create it
$outputFile = $html;
fputs($myfile, $outputFile);
fclose($myfile);
$stat= ' created'; // this is for the list of files displayed in your browser window simply displaying file created
}
echo '<a href="'.$url.'" target="_new">'.$fileTitle.'.html'.$stat.'</a><br/>'; //displays a link to each file hyperlink to page (opens in new window)
}
}
echo ('<br/><h2>Files created from shcematic image file folder.</h2>');
?>
好的,我想我已经设法让它在这里发挥作用了。无论出于什么原因,任何人都可以尝试做类似的事情,欢迎任何进一步的建议或改进
<?php
$dir = opendir ("./images"); //the image directory to read
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.png',1)) {
$fileTitle= basename($file, ".png");
$imageSrc= "./images/schematic/".$file;
$html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$fileTitle.'</title>
</head>
<body>
<div id="image-holder">
<div class="img-title">'.$fileTitle.'</div>
<img src=".'.$imageSrc.'" width="640" height="751" style="border: none;" alt="'.$fileTitle.'-diagram" usemap="#mapFor-'.$fileTitle.'">
<map name="'.$fileTitle.'-imageMap" id="mapFor-'.$fileTitle.'">
<!-------------------------------- '.$fileTitle.' Mapping ------------------------------------->
</map>
</div>
<div id="partsDescription-tabContent" class="content"></div>
<div id="instructions-tabContent" class="content"></div>
<div id="notes-tabContent" class="content"></div>
<div id="stockControl-tabContent" class="content"></div>
</body>
</html>';
$url= './DirectoryForHTMLfiles/'.$fileTitle.'.html';
$f=@fopen($url,"r"); //check to see if file already exists, if it does then close
if($f)
{
fclose($f);
$stat= ' existing'; // this is for the list of files displayed in your browser window simply displaying file exists
}
else {
$myfile = fopen ($url, 'w') or die("Can not open file"); // else if file does not exist create it
$outputFile = $html;
fputs($myfile, $outputFile);
fclose($myfile);
$stat= ' created'; // this is for the list of files displayed in your browser window simply displaying file created
}
echo '<a href="'.$url.'" target="_new">'.$fileTitle.'.html'.$stat.'</a><br/>'; //displays a link to each file hyperlink to page (opens in new window)
}
}
echo ('<br/><h2>Files created from shcematic image file folder.</h2>');
?>
为每个页面创建一个.html似乎有点浪费。为什么一个PHP页面不接受图像文件名作为路径并用html包装该图像?一个文件,许多不同的输出。因为我必须在每个图像上映射区域(面积图),作为指向部件的链接。否则我完全同意。我正在创建的文件元素是通过ajax动态调用到主页面上的。忘了提到这是一个只用于创建基本文件的运行一次代码。为每个页面创建一个.html似乎有点浪费。为什么一个PHP页面不接受图像文件名作为路径并用html包装该图像?一个文件,许多不同的输出。因为我必须在每个图像上映射区域(面积图),作为指向部件的链接。否则我完全同意。我正在创建的文件元素是通过ajax动态调用到主页面上的。忘了提到这是一个运行一次的代码,只是为了创建基本文件。