phpforms

PHP How to get the id from a file input field


I was just wondering how I would go about retrieving the id from an input type file field within PHP.

<input name="images[]" class="browse" type="file" id="0_0">

I need to use the id. I previously was using another input

<input name="ids[]" class="browse" type="hidden" id="0_0">

In conjunction with the file inputs but it was too cumbersome. I had a look at,

print_r($_FILES['images']);

But that didn't have the id stored. And neither does,

$_POST['images'];

Is it possible to retrieve the id of the file inputs?

Thanks


Solution

  • Why not include the ID you're looking for in the name?

    <input name="images[0_0]" class="browse" type="file" id="0_0">
    

    It probably won't break any looping you're doing, and you'll have access to it in the $_POST['images'] array keys.

    As dbf said, it's impossible access the id attribute with PHP after the form has been posted.