0

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?

2 Answers 2

1
  • 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" />

Sign up to request clarification or add additional context in comments.

Comments

0

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" />

4 Comments

I'm using this approach now, but is there's a way to upload all at once? I think I've seen a lot of uploaders that allow this. Upload a bulk of images at once and main one will be the main one. Craigslist, Ebay come to mind.
The problem lies in the interface: how do you tell the system which image is the main, when "pictures[]" means, in fact, "bunch them all together in no particular order"? A different interface might well be able to manage this (I don't think eBay uses plain vanilla input file fields -- I might be mistaken, though). Otherwise you need to either check the images themselves (e.g. find the largest?), or restrict the users to those browsers where the $pictures[0] actually corresponds to the first clicked image, and not the earliest or the first in lexicographic order.
>or restrict the users to those browsers where the $pictures[0] actually corresponds to the first clicked image - that's what's needed. How to make sure which browser does what? It's for inner script for adding products to store, so it's not for users, just for website content creator(s).
The best way would be to experiment. Then, check that $_SERVER['HTTP_USER_AGENT'] matches what you're expecting (because the backend people WILL use a different browser than what you told them to. You have my word on it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.