我想我的產品詳細信息頁面上創建圖像縮略圖像這樣:上傳五張圖片爲一個產品
問:如何解決上傳五張圖片驗證碼爲一個產品?
例:
===================================================
| id | name | img_file |
---------------------------------------------------
| 1 | Shirt | shirt1.jpg, shirt2.jpg, shirt3.jpg |
===================================================
或者我應該創建用於存儲圖像文件名的新表?
moda_add.php
<!-- Button to trigger modal -->
<a class="btn btn-primary" href="#myModal" data-toggle="modal">Click Here To Add</a>
<br>
<br>
<br>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<h3 id="myModalLabel">Add</h3>
</div>
<div class="modal-body">
<form method="post" action="add.php" enctype="multipart/form-data">
<table class="table1">
<tr>
<td><label style="color:#3a87ad; font-size:18px;">FirstName</label></td>
<td width="30"></td>
<td><input type="text" name="p_name" placeholder="p_name" required /></td>
</tr>
<tr>
<td><label style="color:#3a87ad; font-size:18px;">MiddleName</label></td>
<td width="30"></td>
<td><input type="text" name="p_price" placeholder="p_price" required /></td>
</tr>
<tr>
<td><label style="color:#3a87ad; font-size:18px;">LastName</label></td>
<td width="30"></td>
<td><input type="text" name="p_discount" placeholder="p_discount" required /></td>
</tr>
<tr>
<td><label style="color:#3a87ad; font-size:18px;">Address</label></td>
<td width="30"></td>
<td><input type="text" name="p_descp" placeholder="p_descp" required /></td>
</tr>
<tr>
<td><label style="color:#3a87ad; font-size:18px;">Upload Image</label></td>
<td width="30"></td>
<td><input type="file" name="image" required /></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button type="submit" name="Submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
add.php
<?php
ob_start();
session_start();
include('connect.php');
if($_SESSION['logged_in']) {
$ID=$_SESSION['member_id'];
}
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}else{
$file=$_FILES['image']['tmp_name'];
$image = $_FILES["image"] ["name"];
$image_name= addslashes($_FILES['image']['name']);
$size = $_FILES["image"] ["size"];
$error = $_FILES["image"] ["error"];
if ($error > 0){
die("Error uploading file! Code $error.");
}else{
if($size > 10000000) //conditions for the file
{
die("Format is not allowed or file size is too big!");
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);
$p_img=$_FILES["image"]["name"];
$p_name= $_POST['p_name'];
$p_price= $_POST['p_price'];
$p_discount= $_POST['p_discount'];
$p_descp= $_POST['p_descp'];
//$email= $_POST['email'];
mysql_query("insert into fm_product (p_name,p_price,p_discount,p_descp,p_img,p_member_id,p_created_date)
values('$p_name','$p_price','$p_discount','$p_descp','$p_img', '$ID', CURRENT_TIMESTAMP)")or die(mysql_error());
}
header('location:product.php');
}
}
?>
那麼,是什麼問題? – Epodax
「或者我應該創建一個用於存儲圖像文件名的新表?」 - 是的,創建新的表'product_images',其中將包含每個產品的所有圖像名稱 – RomanPerekhrest
_或者我應該創建一個新的表來存儲圖像文件名?_:當然。一個表格單元格不應包含用逗號分隔的多個值。 –