i am using HTML5 multiple upload feature.
<input name='upload[]' type=file multiple="multiple" id="profileImages" />
its working perfect. Now I have one query
does multiple uploading follow any order while uploading images?
suppose I have 5 images
a.png
b.png
c.png
d.png
e.png
now while uploading images if I select images in below order
a.png,
b.png,
e.png,
d.png,
c.png
does these images would be uploaded in the same order I select?
means $_FILES['upload']['name']
array will have (using PHP )
[0] =>'a.png',
[1] =>'b.png',
[2] =>'e.png',
[3] =>'d.png',
[4] = >'c.png'
or it depends upon filesize or browser or any other factor/attribute ?
further i m storing these images individually in profile_image_table
id(pk ) | profile_id | image_name
answer of above question will make my work easy because if multiple image upload in the order we select then it would be easier to choose one image for main profile image ( using MIN(id)
or MAX(id)
) of given profile_id
.
Multipart upload is the process of creating an object by breaking the object data into parts and uploading the parts to HCP individually. The result of a multipart upload is a single object that behaves the same as objects for which the data was stored by means of a single PUT object request.
In Image, click on the drop-down list. Navigate to the desired image and select the image. Click Open. Click Save.
HTML5 has nothing to do with file uploads where the server is concerned. Period. There is no reliable "order." As the comments have noted, the actual order resulting from the new HTML5 multiple
fields can vary from browser to browser. To understand why, we need to look at what happens when a user-agent (browser) submits a form with multiple file fields to a PHP server.
When you upload multiple files from an HTML form your browser is doing a couple of things automatically for you:
Content-Type: multipart/form-data
header to inform the remote HTTP server that it's sending several discrete "blocks" of information within the context of this single request.The raw HTTP message will look something like this:
POST /somePath HTTP/1.1
User-Agent: my-browser-v0.1
Host: www.example.com
Content-Length: 42
Content-Type: multipart/form-data; boundary=--------------------
------------------------------
Content-Disposition: form-data; name="file[]" filename="file1.txt"
Content-Type: text/plain
these were the contents of file1.txt
------------------------------
Content-Disposition: form-data; name="file[]"; filename="file2.txt"
Content-Type: text/plain
these were the contents of file2.txt
It's completely up to the browser in which order it places the data from your form. User-Agent sniffing is not really a viable option to determine the ordering. Instead, if the order of the fields is that important (pointless idea, but whatever), you should use a form in which there are a finite number of possible file fields and name them individually. This way you can access the files by their field names in the $_FILES
array. After all, you aren't required to use the new HTML5 feature just because it exists:
<form action='' method='post' enctype='multipart/form-data'>
<input name='file1' type=file>
<input name='file2' type=file>
<input type='submit'>
</form>
And in your PHP file access the fields directly by their names. You'll know which form field name was first because you coded the HTML that way:
<?php
$_FILES['file1'];
$_FILES['file2'];
Perhaps a better solution in your case would be to simply have one file field that is named directly (so you always know it's the primary field) and then add the multi-select field for users to add further files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With