2012-04-04 95 views
0

我有上传用PHP Zend框架的多个文件的一个问题确定哪些文件接收(多个文件上传zendframwork)

我有其中包含许多输入[类型=“文件”]的标签的形式,每个标签具有其唯一的名称和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? 
} 
} 

请帮忙,谢谢提前。

回答

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变量。 :)

希望有所帮助。

+0

谢谢Pushpesh,但我试过,但是当我打印文件[“文件名”]它没有打印任何东西。 – 2012-04-04 10:02:33

+0

看看这是否可以帮助你 - http://ahsangill.wordpress.com/2009/02/17/zend-framework-file-upload-using-zend_form_element_file/ – 2012-04-04 10:05:39

+0

不幸的是,我一直在使用类似的代码上传,但我仍然解决不了问题,谢谢你的帮助。 – 2012-04-05 09:43:28