简体   繁体   English

如何通过多个文件上传从 php 获取 html 表单名称?

[英]How can I get the html form name from php with multiple file uploads?

If I do something like this to get handle file uploads:如果我做这样的事情来处理文件上传:

if ($_FILES) {
    foreach ($_FILES as $file) {
        //...Handle the upload process
    }
}

Is there any way that I can get the key of the file?有什么方法可以获取文件的密钥吗? As in:如:

<input type="file" name="myfile" />

I want to know that the file is coming from "myfile".我想知道该文件来自“myfile”。

Edit: The obvious solution to this turns out to be:编辑:对此的明显解决方案是:

foreach($_FILES as $key => $file) {

    $input_name = $key;
    // Handle upload.

}

If the input name in your form is myfile , then it will be in the $_FILES array as:如果表单中的输入名称是myfile ,那么它将在$_FILES数组中为:

$_FILES['myfile']

So you can do:所以你可以这样做:

foreach ($_FILES as $inputName => $fileInfo) {

}

Check out Handling file uploads for more info.查看处理文件上传以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM