Topic awaiting preservation: getting assigned key from $_FILES array (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: New Jersey, USA |
posted 05-21-2006 23:47
I have an upload form that allows the user to upload multiple files at once if they want to. I'm using name="photos[]" to have all the uploads in an array on submit. Without going into a huge explaination, I would like to number the keys in the form fields i.e code: name="photos[1]" name="photos[3]" name="photos[7]"
code: foreach ($_FILES['photos'] as $key => $value) { echo $key.'<br />'; }
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 05-22-2006 01:37
I don't think you can put the keys in like that. In this case I don't think you're getting an array you're just getting three values |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 05-22-2006 02:56
Thanks Bit code: foreach ($_FILES['photos'] as $photoArray) { foreach ($photoArray as $key => $value) { echo $key.'-'. $value; } }
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 05-22-2006 23:24
Ah interesting. |
Paranoid (IV) Inmate From: Norway |
posted 05-22-2006 23:30
AFAIR it also work like that for the other kind of form field. |
Maniac (V) Inmate From: there...no..there..... |
posted 05-23-2006 03:51
let me ask a silly question. How are you naming the "picture" fields in the form itself? Just curious. |
Maniac (V) Inmate From: there...no..there..... |
posted 05-23-2006 04:23
never mind. I didn't know you could have the names of the fields as "field[]". |
Nervous Wreck (II) Inmate From: |
posted 05-23-2006 04:58
Yep. It's a feature of PHP. If you add a foo[] or foo[bar] in either a POST variable ( code: name="foo[]" ) or GET variable ( code: ?foo[]=bar ), PHP interprets it appropriately. It's not done by Apache or the browser -- this is a feature of the PHP interpreter itself. |