Note that there are some explanatory texts on larger screens.

plurals
  1. POhaving multiple php file upload in a form keeps carrying first file name to other uploads
    primarykey
    data
    text
    <p>Right i have a form that connects to a php script. With in the form there is multiple inputs such as text, checkbox, dropdown etc. However i also have 3 upload slots for 3 images that get uploaded to a img folder and i just grab the name to store in a mysql database along with the form.</p> <p>here is the form.</p> <pre><code> &lt;form method="post" action="scripts/AddProduct.php" enctype="multipart/form-data"&gt;&lt;table class="table table-bordered table-striped"&gt; &lt;tr&gt; &lt;td align="right"&gt;Category&lt;/td&gt; &lt;td&gt;&lt;label&gt;&lt;select id="pro_catagory" name"pro_catagory"&gt; &lt;?php echo $result; ?&gt; &lt;/select&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;Subcatagory&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;select name="pro_subcategory" id="pro_subcategory"&gt; &lt;option value="Hats"&gt;Hats&lt;/option&gt; &lt;/select&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;Details&lt;/td&gt; &lt;td&gt;&lt;textarea name="pro_details" cols="" rows=""&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;Size&lt;/td&gt; &lt;td&gt; S &lt;input type="hidden" name="pro_size" value="0" /&gt; &lt;input type="checkbox" name="pro_size" value="1" /&gt; M &lt;input type="hidden" name="pro_size_m" value="0" /&gt; &lt;input type="checkbox" name="pro_size_m" value="1" /&gt; L &lt;input type="hidden" name="pro_size_l" value="0" /&gt; &lt;input type="checkbox" name="pro_size_l" value="1" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;Colour&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;input type="text" name="pro_colour" id="colour"/&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;1st Image&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;input type="file" name="file" id="file" /&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;2nd Image&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;input type="file" name="filee" id="filee" /&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right"&gt;3rd Image&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;input type="file" name="file3" id="file3" /&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;label&gt; &lt;input type="submit" name="button" id="button" value="Add This Item Now" /&gt; &lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;/form&gt; </code></pre> <p>(I have shortend down the script so its only examples of what are in the form). Their are a total of 21 options in the form.</p> <p>Foloowing this the php file AddProduct.php.</p> <pre><code> &lt;?php //File Upload 1 if ($_FILES["file"]["error"] &gt; 0) { echo "Error: " . $_FILES["file"]["error"] . "&lt;br&gt;"; } else { echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;"; echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;"; echo "Stored in: " . $_FILES["file"]["tmp_name"] . "&lt;br&gt;&lt;br&gt;"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); } } //File Upload 2 if ($_FILES["filee"]["error"] &gt; 0) { echo "Error: " . $_FILES["filee"]["error"] . "&lt;br&gt;"; } else { echo "Upload: " . $_FILES["filee"]["name"] . "&lt;br&gt;"; echo "Type: " . $_FILES["filee"]["type"] . "&lt;br&gt;"; echo "Size: " . ($_FILES["filee"]["size"] / 1024) . " kB&lt;br&gt;"; echo "Stored in: " . $_FILES["filee"]["tmp_name"] . "&lt;br&gt;&lt;br&gt;"; if (file_exists("upload/" . $_FILES["filee"]["name"])) { echo $_FILES["filee"]["name"] . " already exists. " . "&lt;br&gt;&lt;br&gt;"; } else { move_uploaded_file($_FILES["filee"]["tmp_name"], "upload/" . $_FILES["filee"]["name"]); } } //File Upload 3 if ($_FILES["file3"]["error"] &gt; 0) { echo "Error: " . $_FILES["file3"]["error"] . "&lt;br&gt;"; } else { echo "Upload: " . $_FILES["file3"]["name"] . "&lt;br&gt;"; echo "Type: " . $_FILES["file3"]["type"] . "&lt;br&gt;"; echo "Size: " . ($_FILES["file3"]["size"] / 1024) . " kB&lt;br&gt;"; echo "Stored in: " . $_FILES["file3"]["tmp_name"] . "&lt;br&gt;&lt;br&gt;"; if (file_exists("upload/" . $_FILES["file3"]["name"])) { echo $_FILES["file3"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file3"]["tmp_name"], "upload/" . $_FILES["file3"]["name"]); } } //Rest of php to get the posted values (all still work) ?&gt; </code></pre> <p>My problem is that when its submitted the name of file (image 1) is then followed through to filee and file3 so the output ends like:</p> <pre><code>Upload: testing.jpg Type: image/jpeg Size: 684.8818359375 kB Stored in: C:\wamp\tmp\php41FF.tmp testing.jpg already exists. Upload: Type: Size: 0 kB Stored in: already exists. Upload: Type: Size: 0 kB Stored in: </code></pre> <p>thanks for any help in advance</p> <p>EDIT: this is var_dump</p> <pre><code>array (size=3) 'file' =&gt; array (size=5) 'name' =&gt; string '2Fourk. RV2.jpg' (length=15) 'type' =&gt; string 'image/jpeg' (length=10) 'tmp_name' =&gt; string 'C:\wamp\tmp\php4FD7.tmp' (length=23) 'error' =&gt; int 0 'size' =&gt; int 701319 'fileField2' =&gt; array (size=5) 'name' =&gt; string '2Fourk.jpg' (length=10) 'type' =&gt; string 'image/jpeg' (length=10) 'tmp_name' =&gt; string 'C:\wamp\tmp\php4FD8.tmp' (length=23) 'error' =&gt; int 0 'size' =&gt; int 938840 'fileField3' =&gt; array (size=5) 'name' =&gt; string 'fiverrgigs.png' (length=14) 'type' =&gt; string 'image/png' (length=9) 'tmp_name' =&gt; string 'C:\wamp\tmp\php4FE9.tmp' (length=23) 'error' =&gt; int 0 'size' =&gt; int 18322 </code></pre>
    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.
 

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