There are several fields:

<input type="file" name="file1" /> <input type="file" name="file2" /> <input type="file" name="file3" /> 

Is it possible to get their name tag in php? And How?

    1 answer 1

    When you send this form to the server, you will have an array of $_FILES , in which the keys will be these three (or how many of them) fields, and the values ​​will be the data about the downloaded files.

    Here is your form:

     <form enctype="multipart/form-data" method="post"> <input type="file" name="file1" /> <input type="file" name="file2" /> <input type="file" name="file3" /> <input type="submit"> </form> 

    In file2 I enter the PNG file and send it. In the variable $_FILES I get

     array(3) { ["file1"]=> array(5) { ["name"]=> string(0) "" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(4) ["size"]=> int(0) } ["file2"]=> array(5) { ["name"]=> string(12) "download.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpVvZcNz" ["error"]=> int(0) ["size"]=> int(336) } ["file3"]=> array(5) { ["name"]=> string(0) "" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(4) ["size"]=> int(0) } } 
    • and how to get this variable? $ _FILES [0] does not work .. I need to output this variable in foreach - Sdafs Fasafs
    • And it does not need to receive. She is. It's like $_POST , $_GET , $_REQUEST . ( php.net/manual/en/reserved.variables.php ) If you send a form to the server in which enctype="multipart/form-data" , then $_FILES variable will be. However, note that this is an ASSOCIATIVE array. Those. you need not $_FILES[0] , but foreach($_FILES as $field=>$fieldData){ - cyadvert
    • If I do this, field shows 0, and fieldData shows the key itself, but the content itself disappears - Sdafs Fasafs
    • it means something is wrong ... Make sure that the enctype is correct, that the form is post ... Try var_dump($_FILES) , look at the contents ... - cyadvert