我将一些图像存储在数组中并显示为每次刷新时图像被洗牌。现在我想存储我使用php从屏幕中选择的图像。请帮帮我。这是代码
<?php
$images = array(
'<a href='#'><img src="images/images (4).jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/images (6).jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/images (5).jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/drt.jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/rf.jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/yu.jpg" alt="" width="234" height="212" /></a>',
'<a href='#'><img src="images/ed.jpg" alt="" width="234" height="212" /></a>');
shuffle($images); // Randomize images array;
?>
<?php echo $images[0];?>
<?php echo $images[1];?>
<?php echo $images[2];?>
答案 0 :(得分:0)
尝试这种方式:
$images = array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
shuffle($images); // for randomaize
//save $images[0], $images[1], into database here
// and echo here..
echo "<img src=\"images/$images[0]\" alt=\"\" width=\"234\" height=\"212\" />\n";
echo "<img src=\"images/$images[0].jpg\" alt=\"\" width=\"234\" height=\"212\" />\n";
答案 1 :(得分:0)
您可以使用复选框将每个img
打包在标签中,并像简单的html表单一样发送选择。但在此之前,你必须以某种方式识别图像,即图像文件名。例如:
.image-select-form input[type=checkbox] {
position:absolute;
visibility: hidden;
}
.image-select-form label {
cursor: pointer;
position: relatice;
display: inline-block;
border: 2px solid rgba(0, 0, 0, 0)
}
.image-select-form label img{
display: block;
}
.image-select-form input[type=checkbox]:checked + label {
border-color: red;
}
&#13;
<form action="select.php" method="post" class="image-select-form">
<div>
<input type="checkbox" name="selected_images" value="rf.jpg" checked id="img1">
<label for="img1"><img src="images/rf.jpg" alt="" width="234" height="212" /></label>
<input type="checkbox" name="selected_images" value="drt.jpg" id="img2">
<label for="img2"><img src="images/drt.jpg" alt="" width="234" height="212" /></label>
<input type="checkbox" name="selected_images" value="yu.jpg" id="img3">
<label for="img3"><img src="images/yu.jpg" alt="" width="234" height="212" /></label>
<input type="checkbox" name="selected_images" value="ed.jpg" id="img4">
<label for="img4"><img src="images/ed.jpg" alt="" width="234" height="212" /></label>
</div>
<input type="submit" value="Submit selected images">
</form>
&#13;
在处理表单的php中,select.php
只访问存储所选图像文件名的$_POST['selected_images']