每当将新图像添加到服务器存储的图像文件夹时,如何使用PHP或任何其他服务器端脚本来创建自动html标记

时间:2017-02-13 04:36:30

标签: php html perl python-3.x

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
</head>
<body class="layouts" id="www-cssplay-co-uk">
    <div id="header">
        <h1>Demo</h1>
        <div id="menu">
            <ul class="main"></ul>
        </div>
    </div>
    <div id="wrapper">
        <input checked="checked" id="pic1" name="large" type="radio"> 
        <input id="pic2" name="large" type="radio">
        <input id="pic3" name="large" type="radio">
        <input id="pic4" name="large" type="radio"> 
        <input id="pic5" name="large" type="radio"> 
        <input id="pic6" name="large" type="radio"> 
        <input id="pic7" name="large" type="radio"> 
        <input id="pic8" name="large" type="radio"> 
        <input id="pic9" name="large" type="radio"> 
        <input id="pic10" name="large" type="radio"> 
        <input id="pic11" name="large" type="radio"> 
        <input id="pic12" name="large" type="radio"> 
        <input id="pic13" name="large" type="radio"> 
        <input id="pic14" name="large" type="radio"> 
        <input id="pic15" name="large" type="radio"> 
        <input id="pic16" name="large" type="radio"> 
        <input id="pic17" name="large" type="radio">
        <input id="pic18" name="large" type="radio"> 
        <input id="pic19" name="large" type="radio">
        <input id="pic20" name="large" type="radio">
        <input id="pic21" name="large" type="radio">
        <input id="pic22" name="large" type="radio">
        <div id="main">
            <div id="main-scroll">
                <div class="main-inner"><img alt="" src="images/1.jpg"></div>
                <div class="main-inner"><img alt="" src="images/2.jpg"></div>
                <div class="main-inner"><img alt="" src="images/3.jpg"></div>
                <div class="pad-bottom"></div>
            </div>
        </div><!--
        -->
        <div id="info">
            <div id="info-scroll">
                <div class="pad-top"></div>
                <div class="info-inner">
                    <label for="pic1">
                     <img alt="" src="images/1.jpg"></label>
                </div>
                <div class="info-inner">
                    <label for="pic2"><img alt="" src="images/2.jpg"></label>
                </div>
                <div class="info-inner">
                    <label for="pic3"><img alt="" src="images/3.jpg"></label>
                </div>  
                <div class="pad-bottom"></div>
            </div>
        </div>
    </div>
    <div id="footer">
        <ul class="sub"></ul>
    </div>
</body>
</html>

图像文件夹托管在服务器端。它目前有3张图片。我想编写一个php脚本,在将新图像添加到文件夹时执行两项操作。 1,它会自动在'main-inner'div区域中创建一个“<div class="main-inner"><img alt="" src="images/x.jpg"></div>”标签(其中'x.jpg'将是新图像)。 2,在'info-inner'div区域中添加<div class="info-inner"><label for="pic3"><img alt="" src="images/x.jpg"></label></div>标记。

2 个答案:

答案 0 :(得分:1)

您可以在页面加载时读取文件夹内容,然后为文件夹中的每个文件生成代码。

这样的事情应该让你开始:

controller: :item_configuration

答案 1 :(得分:1)

首先在服务器上的某个文件夹中创建一个目录 注意:您可以添加许多图像,此代码将显示粘贴在该文件夹上的所有图像。

&#13;
&#13;
 <?php 
$directory = "C:/wamp/www/Test/images/";
$images = glob($directory . "*.jpg");
$count = count($images)+1;
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
</head>
<body class="layouts" id="www-cssplay-co-uk">
    <div id="header">
        <h1>Demo</h1>
        <div id="menu">
            <ul class="main"></ul>
        </div>
    </div>
    <div id="wrapper">
	<?php foreach($images as $key=>$value)
	{ 
		$whatIWant = substr($value, strpos($value, "C:/wamp/www/") + 12);   
		$count = $key+1;
		$cnt = '<input id="pic'.$count.'" name="large" type="radio">';
		echo $cnt;
	 ?>
        <div id="main">
            <div id="main-scroll">
<?php 
echo "<div class='main-inner'><img src='http://localhost/".$whatIWant."' alt='' heught=50px width=50px></div>";
} ?>

    </div>
    <div id="footer">
        <ul class="sub"></ul>
    </div>
</body>
</html>
&#13;
&#13;
&#13;