0

I am building a simple CMS for a client. They need the ability to manage employee profiles.

Each profile needs an image.

Currently I have a form for adding employees, and associating an uploaded image with a single record is easy.

Below the record add form, I have a list of existing records (and a thumbnail of the image). These records are printed between form tags, I've got a checkbox next to each record (marking it will delete it when the form submits).

I want to use this form to also UPDATE records; deletions occur first, then $_POST data is parsed and records updated.

When a record has no image associated with it, instead of a thumbnail, a file input tag is printed. Because there is a variable number of records, the file tags are all named image[] so I can easily loop through them.

Question: how do I correlate $_FILES data with $_POST data? Do I have to name each file input to image_<?=$record_id?> to determine which record the file belongs to?

4 Answers 4

1

Your solution looks good, i would add record id as index, for ex:

image[<?=$record_id?>];

You can then correlate by array index

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

Comments

0

instead of

<input name="image[]">

use assocative array, for ex.:

<input name="image[id_<?=$record_id?>]">

Comments

0

Using the default fieldname[] notation, you can't control what indexes PHP assigns to the server-side representations in POST/GET/REQUEST/FILES. PHP'll just add them sequentially and if there's a gap in your form, it'll be gone once the data hits the server.

You can, hoever, FORCE indexes, so that fieldname[7] and newimage[7] all relate to the same fieldset in your form.

Comments

0

You will need to name each file input, and access it via $FILES['unique_name'].

Comments

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.