0

我在使用 php zend 框架上传多个文件时遇到问题

我有一个包含许多 input[type="file"] 标签的表单,每个标签都有其唯一的名称和 id 属性。

当接收到这些数据时,所有文件都聚集在一个数组文件中,我现在可以轻松地接收和存储它,但这里的问题是我如何识别哪个文件来自哪个输入元素?知道这一点对我来说非常重要,因为每个特定文件都将存储在我数据库的特定字段中。

这是一个例子

<input type "file" name = "main_photo"/>
<input type "file" name = "horizontal_plan"/>


$upload = new Zend_File_Transfer_Adapter_Http();
$files = $upload->getFileInfo();
foreach ($files as $file => $info)
{
if($upload->isValid($file))
{
//here how can i point to the main_photo file or the horizontal_plan file?
}
}

请帮忙,提前谢谢你。

4

1 回答 1

0

你可以看到它们如下:

PHP 打印 $_FILES

Array
(
    [s1] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [s2] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)

<!--HTML FORM-->
<form method="post" enctype="multipart/form-data" action="t23.php">
    <input type="file" name="s1">
    <input type="file" name="s2">
    <input type="submit">
</form>

如您所见,html 文件变量 s1 和 s2 成为一个数组,在 PHP 中具有自己的数据集....您应该很容易确定每个数组对应于 html 中的 namsake 变量。:)

希望有帮助。

于 2012-04-04T09:22:14.693 回答