Php Zend Framework 2:上载和重命名多个文件

Php Zend Framework 2:上载和重命名多个文件,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,我有一个Zend表单,并提供使用该表单上载多个文件的选项。我使用dropzone.js。当我上传一个文件时,一切正常,我得到了Post数据,文件被重命名并移动到正确的文件夹中,但当我上传两个文件时,我会收到一条错误消息:注意:数组到字符串的转换指向$upload->addFilters('file\Rename') 我做错了什么?我的每件事都在一个foreach循环中,这不应该解决问题吗?我找不到解决方法。有人给我一个提示吗 这里是我迄今为止的源代码: $upload = new \Ze

我有一个Zend表单,并提供使用该表单上载多个文件的选项。我使用dropzone.js。当我上传一个文件时,一切正常,我得到了Post数据,文件被重命名并移动到正确的文件夹中,但当我上传两个文件时,我会收到一条错误消息:注意:数组到字符串的转换指向$upload->addFilters('file\Rename')

我做错了什么?我的每件事都在一个foreach循环中,这不应该解决问题吗?我找不到解决方法。有人给我一个提示吗

这里是我迄今为止的源代码:

    $upload = new \Zend\File\Transfer\Adapter\Http();

    // Limit the amount of files
    $upload->addValidator('Count', false, 2);

    // Limit the MIME type of all given files to gif and jpeg images
    $upload->addValidator('MimeType', false, array('image/gif', 'image/jpeg',));

    if (!$upload->isValid()) {
        $data = new JsonModel(array(
            'success' => "failed",
            'message' =>  "validation failed",
            ));
            return $data;

    }else{
         $files  = $upload->getFileInfo();
         $upload->setDestination('./public/uploads/tmp/');

         // loop through the file array
         foreach ($files as $file => $info)  {

           $file_ext = @strtolower(@strrchr($originalName,"."));                 
           $file_ext = @substr($file_ext, 1); // remove dot

           $newFilename = md5(uniqid(rand(), true)) .time(). '.' . $file_ext;

           $upload->addFilter('File\Rename', 
                    array('target' => $upload->getDestination() . DIRECTORY_SEPARATOR . $newFilename,
                   'overwrite' => true));

           if (!$upload->receive()) {
                $data = new JsonModel(array(
                                'success' => "upload failed",
                        ));
           }else{
                $data = new JsonModel(array(
                                'success' => "upload ok",                           
                        ));
           }
           return $data;
          } // end foreach
      }