I have a large body of technical illustrations that I need to Map area to form an online manual. I have already made the base engine for linking each file together and navigating forward and backwards. But due to the large amount of images I wanted to create a group of base HTML files that I could then go through and edit the relevant sections.
What I wanted was to search the directory (images/schematic/) and create a HTML file for each image (imagefilename.png). The file would use the name of the image (imagefilename). The body of the html file would be similar to as follows.
$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> ';
I found this code which did display a list of the files, and found out that it is the 'basename' that is removing the directory name.
<?php
$directory = "./images/schematic/";
$directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory;
$files = glob($directory);
for($i=0;$i<sizeof($files) ; $i++){
echo basename($files[$i])."<br/>
";
}?>
But I do not understand how to do something to each return value from the image file search. As you can probably tell I have little to no idea when it comes to php but I am trying. If someone could point me in the right direction explaining how and why I would appreciate it.
Ok I have had a bit of a breakthrough. This code does work. Now I would like to tweek it. Suggestions on how to improve it are more than welcome.
<?php
$directory = "./images/schematic/";
$directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory;
$files = glob($directory);
for($i=0;$i<sizeof($files) ; $i++)
{
$fileTitle= basename($files[$i], ".png");
$imageSrc= $files[$i];
$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>'.$pageTitle.'</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.'">
<!-------------------------------- '.$pageTitle.' 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>';
$myfile = fopen ('./newdirectory/'.$fileTitle.'.html', 'w') or die("Can not open file");
$outputFile = $html;
fputs($myfile, $outputFile);
fclose($myfile);
};
echo ("OK Files created")
?>
I have cobbled this together from various tutorials I found across the web. I would like it to only look image files, preferably .png and .jpeg. Can I get it to skip a file that exists (I am thinking for further down the line in case I have area mapped the images and it is overwritten.) I realize this may look messy but I am a complete newb to this.