我需要一个目录脚本。我到处找,但似乎找不到适合我需要的那个。我需要将多个(无限)图像上传到服务器,同时将产品名称、描述等和一行中的多个图像路径保存到数据库。
如果可能的话,我想使用这个无限上传图片 -->
<input type="file" name="img[]" multiple>
图片上传
- 文件最大大小:2048kb
- 文件类型:jpg/png/gif
- 上传文件夹:[category]/image[random_number].jpg
数据库
产品
- ID
- 产品
- 描述
- 类别
- 材料
- 颜色
- 尺寸
- 风格
- 股票
- ws_price
- rt_price
- 多个图像路径
类别
- cat_id
- parent_id
- 类别
- 描述
文件
- add_product.php
- view_product.php
- add_category.php
- db_connect.php
- 上传.php
- .sql
如果您知道已经为此或类似设置的任何脚本,并且只需要稍作调整,那么如果您可以给我发送链接,那就太好了。:)
我之前已经整理了一个文件上传脚本,但它非常草率,我不得不分开上传文件[]。这是很久以前的旧版本:
<?php
$con = mysql_connect("localhost","","");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("test", $con);
$random_digit = rand(0000,9999);
$target = 'images/';
$px = array();
echo "<ul>";
for($i = 0; $i < 10; $i ++ )
{
$px[$i] = "";
$pic[$i+1] = ($_FILES["image" . ($i + 1)]["name"]);
if (empty($pic[$i + 1]))
{
echo "<li>IMG $i + 1 EMPTY </li>";
}
else
{
$px[$i] = $random_digit . $pic[$i + 1];
$px[$i] = preg_replace('/\s+/','_', $px[$i]);
$px[$i] = str_replace('&', 'and', $px[$i]);
$u = $target . $px[$i];
$result = move_uploaded_file($_FILES['image' . ($i + 1)]['tmp_name'], $u);
echo "<li>IMG " . ($i + 1) . " Uploaded</li>";
}
}
echo "</ul>";
$itemnumber=mysql_real_escape_string($_POST['itemnumber']);
$product=mysql_real_escape_string($_POST['product']);
$category=mysql_real_escape_string($_POST['category']);
$color=mysql_real_escape_string($_POST['color']);
$style=mysql_real_escape_string($_POST['style']);
$material=mysql_real_escape_string($_POST['material']);
$sizes=mysql_real_escape_string($_POST['sizes']);
$stocks=mysql_real_escape_string($_POST['stocks']);
$orders=mysql_real_escape_string($_POST['orders']);
$wsprice=mysql_real_escape_string($_POST['wsprice']);
$rtprice=mysql_real_escape_string($_POST['rtprice']);
$profit=mysql_real_escape_string($_POST['profit']);
$itemcode=mysql_real_escape_string($_POST['itemcode']);
$suppliers=mysql_real_escape_string($_POST['suppliers']);
$dc=mysql_real_escape_string($_POST['dc']);
$sql = "INSERT INTO `items` (itemnumber, product, category, color, style, material, sizes, stocks, orders, wsprice, rtprice, profit, itemcode, suppliers, dc, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10) VALUES ('$itemnumber', '$product', '$category', '$color', '$style', '$material', '$sizes', '$stocks', '$orders', '$wsprice', '$rtprice', '$profit', '$itemcode', '$suppliers', '$dc', '$px[0]', '$px[1]', '$px[2]', '$px[3]', '$px[4]', '$px[5]', '$px[6]', '$px[7]', '$px[8]', '$px[9]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<ul>";
echo "<li>Item #: " . $itemnumber . "</li>";
echo "<li>Product: " . $product . "</li>";
echo "<li>Category: " . $category . "</li>";
echo "<li>Style: " . $style . "</li>";
echo "<li>Material: " . $material . "</li>";
echo "<li>Sizes: " . $sizes . "</li>";
echo "<li>Stocks: " . $stocks . "</li>";
echo "<li>Orders: " . $orders . "</li>";
echo "<li>WS Price: " . $wsprice . "</li>";
echo "<li>RT Price: " . $rtprice . "</li>";
echo "<li>Profit: " . $profit . "</li>";
echo "<li>Item Code: " . $itemcode . "</li>";
echo "<li>Suppliers: " . $suppliers . "</li>";
echo "<li>DC: " . $dc . "</li>";
echo "</ul>";
mysql_close($con);
?>
报名表
<form enctype="multipart/form-data" action="add.php" method="POST">
<input type="hidden" name="id" value="" />
<table border="0" cellpadding="3">
<th colspan="3">Shop Item Entry</th>
<tr><td>Item # <input type="text" name="itemnumber" size="27" value="01-00000"> </td>
<td>Product <input type="text" name="product" size="100"></td>
</tr>
<tr>
<td>Category <?php
$con = mysql_connect("localhost","","");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("test", $con);
function finddepth($byid) {
$re_query=mysql_query("SELECT * FROM categories where parent_id='$byid'");
$num_rows = mysql_num_rows($re_query); //echo " Has children:".$num_rows."<br>";
if(mysql_num_rows($re_query) > '0') {
while($recursive_rw=mysql_fetch_array($re_query)){
$p=$recursive_rw['category_id'];
$catnm=$recursive_rw['title'];
$parent=$recursive_rw['parent_id'];
$pre="- - ";
if($parent=="0") {
?>
<option><?php echo $catnm; ?></option>
<?php
} else {
echo '<option value="'.$catnm.'">'.$pre.$catnm.'</option>' ;
}
finddepth($p);
}//end while
}//end if
}//end of function
?><select name="category">
<option values=" "> </option>
<?php finddepth(0); ?>
</select>
</td>
<td>Color <input type="text" name = "color"size="45"> Style <input type="text" name = "style" size="45"></td>
</tr>
<tr>
<td> Material <input type="text" name = "material" size="25"></td>
<td>
Sizes <input type="text" name = "sizes" size="46"> Stocks <input type="text" name = "stocks" size="15"> Orders <input type="text" name = "orders" size="14">
</td>
</tr>
<tr>
<td colspan="3">
WS Price <input type="text" name = "wsprice" size="24"> RT Price <input type="text" name = "rtprice"> Profit <input type="text" name = "profit"> DC: <input type="radio" name="dc" value="Yes"> Yes <input type="radio" name="dc" value="No" checked> No
</td>
</tr>
<tr>
<td> Item Code: <input type="text" name = "itemcode" size="22"></td>
<td>Suppliers: <input type="text" name = "suppliers" size="100"></td>
</tr>
<tr>
<td colspan="3">
<input size="25" name="image1" type="file" />
<input size="25" name="image2" type="file" />
<input size="25" name="image3" type="file" />
<input size="25" name="image4" type="file" />
<input size="25" name="image5" type="file" />
<input size="25" name="image6" type="file" />
<input size="25" name="image7" type="file" />
<input size="25" name="image8" type="file" />
<input size="25" name="image9" type="file" />
<input size="25" name="image10" type="file" />
</td>
</tr>
</table>
<input type="submit" name="submit" value="Add">
</form>
这个正在工作,但是所有“上传文件”的东西都非常混乱,如果可能的话,还添加了无限图像上传的功能功能,而不是仅仅 10 张,因为有些产品需要超过 10 张图片。任何事情都可以提供帮助,所以如果您能帮助我处理这两个文件,我将不胜感激。谢谢!
*谁能告诉我如何在一行中保存多个数据(图像路径)。
例如:img_path: "img1.jpg, img2.jpg, img3.jpg"
$img_path = implode(',', $_POST['img[]']);
INSERT INTO products (id, product, description, img_path)
VALUES ('$id',$product','$description','$img_path')
这行得通吗?我还没来得及测试它。