Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For uploading multiple files its better to use input field names as array, so the uploaded files will be well organized as an array that can be easily handled. So your upload form should look something like this</p> <p><code>&lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt; Image1: &lt;input name="image[]" type="file" /&gt;&lt;br /&gt; Image2: &lt;input name="image[]" type="file" /&gt;&lt;br /&gt; Image3: &lt;input name="image[]" type="file" /&gt;&lt;br /&gt; Image4: &lt;input name="image[]" type="file" /&gt;&lt;br /&gt; Image5: &lt;input name="image[]" type="file" /&gt;&lt;br /&gt; &lt;input type="submit" value="Upload" /&gt; &lt;/form&gt;</code></p> <p>And in the upload.php</p> <pre><code>if($_FILES['image']) { //organise the array :: refer http://php.net/manual/en/features.file-upload.multiple.php for more details $images = reArrayFiles($_FILES['image']); $image_count = count($_FILES['image']['name']); for ($i = 0; $i &lt; $image_count; $i++) { if($images[$i]['name']!='' &amp;&amp; $images[$i]['tmp_name']!='') { $path = 'upload/products/'; $saved = 0; # Upload file to folder $filename = basename($images[$i]['tmp_name']); $filename_array = explode('.', $filename); $ext = strtolower(end($filename_array)); $image_name = date('YmdHis').'.'.$ext; //random file naming if(in_array(strtoupper($ext), $allowed_ext)) { $folder = $path . $image_name; $saved = move_uploaded_file($images[$i]['tmp_name'], $folder); } if($saved) { $sql = "INSERT INTO product_images (product_id,name,images) VALUES ($current_id,'$image_name', '$folder')"; if(mysql_query($sql)) echo "successfull"; } else { echo 'Failed to upload file'; } } } } function rearrange( $arr ){ foreach( $arr as $key =&gt; $all ){ foreach( $all as $i =&gt; $val ){ $new[$i][$key] = $val; } } return $new; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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