Paul G
Paul G

Reputation: 1

PHP image upload with proper order

I have a simple script for eCommerce website that uploads images for products.

<input type="file" name="pictures[]" multiple="multiple" />

Everything works absolutely fine, and multiple images are uploaded at once.

However, there's one major problem. Script (or Win10 I am using) doesn't not remember which image I clicked first. It doesn't 'remember' the order. For internet stores it's extremely important to keep main image main - so main image should be a specific image out of the set of these images.

What's the solution to this?

Upvotes: 0

Views: 444

Answers (2)

user10451858
user10451858

Reputation:

  • you just shouldn't count on the browser for it, try make two fields with different name attribute like :

    <input type="file" name="main" />
    <input type="file" name="pictures[]" multiple="multiple" />

Upvotes: 1

LSerni
LSerni

Reputation: 57418

You can't leave that to the browser, as there is no standard order that's guaranteed.

What you need to do is to use two different fields:

<input type="file" name="mainpicture" />

<input type="file" name="pictures[]" multiple="multiple" />

Upvotes: 0

Related Questions