Note that there are some explanatory texts on larger screens.

plurals
  1. POUnlimited image upload to server & name, categories, etc & multiple image path (1 row) to db
    primarykey
    data
    text
    <p>I need a catalog script. I've looked everywhere but I can't seem to find the right one for what I need. I need to upload multiple (unlimited) images to server while saving the product name, description, etc and mulitple image path in one row to db.</p> <p>If possible, I would like to have unlimited image upload using this --></p> <pre><code> &lt;input type="file" name="img[]" multiple&gt; </code></pre> <p><strong>Image Upload</strong></p> <ul> <li>Files Max Size: 2048kb</li> <li>File Type: jpg/png/gif</li> <li>Upload Folder: [category]/image[random_number].jpg </li> </ul> <p><strong>Database</strong></p> <p><strong>Products</strong></p> <ul> <li>id</li> <li>product</li> <li>description</li> <li>category</li> <li>material</li> <li>color</li> <li>size</li> <li>style</li> <li>stock</li> <li>ws_price</li> <li>rt_price</li> <li>multiple_image_path</li> </ul> <p><strong>Categories</strong></p> <ul> <li>cat_id</li> <li>parent_id</li> <li>category</li> <li>description</li> </ul> <p><strong>Files</strong></p> <ul> <li>add_product.php </li> <li>view_product.php</li> <li>add_category.php</li> <li>db_connect.php</li> <li>upload.php</li> <li>.sql</li> </ul> <p>If you know any scripts that are already set up for this or similar, and just need a little tweaking, it would be great if you can send me a link. :)</p> <p>I had put together a file upload script before but it's pretty sloppy and I had to separate the upload files[]. Here's the old one from a long time ago:</p> <pre><code> &lt;?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 "&lt;ul&gt;"; for($i = 0; $i &lt; 10; $i ++ ) { $px[$i] = ""; $pic[$i+1] = ($_FILES["image" . ($i + 1)]["name"]); if (empty($pic[$i + 1])) { echo "&lt;li&gt;IMG $i + 1 EMPTY &lt;/li&gt;"; } else { $px[$i] = $random_digit . $pic[$i + 1]; $px[$i] = preg_replace('/\s+/','_', $px[$i]); $px[$i] = str_replace('&amp;', 'and', $px[$i]); $u = $target . $px[$i]; $result = move_uploaded_file($_FILES['image' . ($i + 1)]['tmp_name'], $u); echo "&lt;li&gt;IMG " . ($i + 1) . " Uploaded&lt;/li&gt;"; } } echo "&lt;/ul&gt;"; $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 "&lt;ul&gt;"; echo "&lt;li&gt;Item #: " . $itemnumber . "&lt;/li&gt;"; echo "&lt;li&gt;Product: " . $product . "&lt;/li&gt;"; echo "&lt;li&gt;Category: " . $category . "&lt;/li&gt;"; echo "&lt;li&gt;Style: " . $style . "&lt;/li&gt;"; echo "&lt;li&gt;Material: " . $material . "&lt;/li&gt;"; echo "&lt;li&gt;Sizes: " . $sizes . "&lt;/li&gt;"; echo "&lt;li&gt;Stocks: " . $stocks . "&lt;/li&gt;"; echo "&lt;li&gt;Orders: " . $orders . "&lt;/li&gt;"; echo "&lt;li&gt;WS Price: " . $wsprice . "&lt;/li&gt;"; echo "&lt;li&gt;RT Price: " . $rtprice . "&lt;/li&gt;"; echo "&lt;li&gt;Profit: " . $profit . "&lt;/li&gt;"; echo "&lt;li&gt;Item Code: " . $itemcode . "&lt;/li&gt;"; echo "&lt;li&gt;Suppliers: " . $suppliers . "&lt;/li&gt;"; echo "&lt;li&gt;DC: " . $dc . "&lt;/li&gt;"; echo "&lt;/ul&gt;"; mysql_close($con); ?&gt; </code></pre> <p>Entry Form</p> <pre><code> &lt;form enctype="multipart/form-data" action="add.php" method="POST"&gt; &lt;input type="hidden" name="id" value="" /&gt; &lt;table border="0" cellpadding="3"&gt; &lt;th colspan="3"&gt;Shop Item Entry&lt;/th&gt; &lt;tr&gt;&lt;td&gt;Item # &lt;input type="text" name="itemnumber" size="27" value="01-00000"&gt; &lt;/td&gt; &lt;td&gt;Product &lt;input type="text" name="product" size="100"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Category &lt;?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."&lt;br&gt;"; if(mysql_num_rows($re_query) &gt; '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") { ?&gt; &lt;option&gt;&lt;?php echo $catnm; ?&gt;&lt;/option&gt; &lt;?php } else { echo '&lt;option value="'.$catnm.'"&gt;'.$pre.$catnm.'&lt;/option&gt;' ; } finddepth($p); }//end while }//end if }//end of function ?&gt;&lt;select name="category"&gt; &lt;option values=" "&gt; &lt;/option&gt; &lt;?php finddepth(0); ?&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt;Color &lt;input type="text" name = "color"size="45"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Style &lt;input type="text" name = "style" size="45"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Material &lt;input type="text" name = "material" size="25"&gt;&lt;/td&gt; &lt;td&gt; Sizes &lt;input type="text" name = "sizes" size="46"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Stocks &lt;input type="text" name = "stocks" size="15"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Orders &lt;input type="text" name = "orders" size="14"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt; WS Price &lt;input type="text" name = "wsprice" size="24"&gt;&amp;nbsp;RT Price &lt;input type="text" name = "rtprice"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Profit &lt;input type="text" name = "profit"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DC: &lt;input type="radio" name="dc" value="Yes"&gt; Yes &lt;input type="radio" name="dc" value="No" checked&gt; No &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Item Code: &lt;input type="text" name = "itemcode" size="22"&gt;&lt;/td&gt; &lt;td&gt;Suppliers: &lt;input type="text" name = "suppliers" size="100"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt; &lt;input size="25" name="image1" type="file" /&gt; &lt;input size="25" name="image2" type="file" /&gt; &lt;input size="25" name="image3" type="file" /&gt; &lt;input size="25" name="image4" type="file" /&gt; &lt;input size="25" name="image5" type="file" /&gt; &lt;input size="25" name="image6" type="file" /&gt; &lt;input size="25" name="image7" type="file" /&gt; &lt;input size="25" name="image8" type="file" /&gt; &lt;input size="25" name="image9" type="file" /&gt; &lt;input size="25" name="image10" type="file" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" name="submit" value="Add"&gt; &lt;/form&gt; </code></pre> <p>This one is working, but it's very cluttered with all the "upload files" thing and also if possible to add the feature of <strong>unlimited image upload</strong> instead of just 10 because some products have a lot more than 10 pictures needed. Anything can help so I would appreciate if you can just help me with these two files. Thank you!</p> <p>*Can anyone tell me how to save multiple data (image path) in one row. </p> <p>For example: img_path: "img1.jpg, img2.jpg, img3.jpg"</p> <pre><code> $img_path = implode(',', $_POST['img[]']); INSERT INTO products (id, product, description, img_path) VALUES ('$id',$product','$description','$img_path') </code></pre> <p>Would this work? I haven't gotten around to test it yet.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload