简体   繁体   English

如何上传多个文件夹中的一个文件?

[英]How to upload one file in multiple folders?

How to upload one file in multiple folders using zendframe work.如何使用 zendframe work 在多个文件夹中上传一个文件。 When I tried image saving only in main folder, not saving in sub folders.当我尝试仅将图像保存在主文件夹中,而不是保存在子文件夹中时。 Here is the code I had used in my controller.这是我在控制器中使用的代码。

 $apt    = new Zend_File_Transfer_Adapter_Http();
 $files  = $apt->getFileInfo();
 foreach($files as $file => $fileInfo) {
      $apt->addFilter('Rename', array('target' => 'images/practice/'.$fileInfo['name'],'overwrite' => true));
      $apt->addFilter(new Zend_Filter_File_Resize(array('width' => 500,'height' => 600  ,'keepRatio' => true,'directory'=>'images/practice/small/', 'overwrite'=>true)));
      $apt->addFilter(new Zend_Filter_File_Resize(array('width' => 300,'height' => 300,'keepRatio' => true,'directory'=>'images/practice/thumbs/', 'overwrite'=>true)));
 if ($apt->isUploaded($file)) {
            if ($apt->isValid($file)) {
                if ($apt->receive($fileInfo['name'])) {
                     $info = $apt->getFileInfo($file);
                }
             }
         }
         else{
         echo 'not uploaded<br>';
         }
    }

Please help me out, Thanks in advance.请帮助我,提前致谢。

I think you should write your own filters for this.我认为您应该为此编写自己的过滤器。 I haven't check the source of the current filters, but they all rename/move the file instead of copying it.我没有检查当前过滤器的来源,但它们都重命名/移动文件而不是复制它。 If you would like create thumbnails of an image, you should probably extend Zend's resize filter and copy the result to the target directory instead of moving/copying it.如果您想创建图像的缩略图,您可能应该扩展 Zend 的调整大小过滤器并将结果复制到目标目录而不是移动/复制它。 It should not be very difficult to extend this class and change a few lines.扩展这个类并更改几行应该不是很困难。

Once you did, you should use your own resize filter, instead of ZF's one.完成后,您应该使用自己的调整大小过滤器,而不是 ZF 的过滤器。 Watch the order in which you add the filters.注意添加过滤器的顺序。 If you rename the file first, I'm not a 100% sure if your own resize filter can determine the file's location.如果您先重命名文件,我不能 100% 确定您自己的调整大小过滤器是否可以确定文件的位置。

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

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