2012-03-12 42 views
1

当使用Zend的是这样的:Zend框架 - Zend_File_Transfer上传处理程序

$upload = new Zend_File_Transfer_Adapter_Http(); 
$upload->setDestination('/some/directory'); 
$upload->addValidator(x) 
->addValidator(y); 
$upload->receive(); 

首先上传到tmp目录下上传的文件,验证,然后转移到“一些/目录”或直接保存进入setDestination目录?如果是前者,在我看来,它在上传到tmp目录后与“move_uploaded_file”的作用相同。

ZF是否提供某种类型的http流处理程序来将文件原生写入特定的目录?即类似于nodejs或django?

回答

2

Zend_File_Transfer_Adapter_Http使用move_uploaded_file经验证人验证后,您分配。

here

public function receive($files = null) 
{ 
    if (!$this->isValid($files)) { 
     return false; 
    } 
    ... some code ... 

    if (!move_uploaded_file($content['tmp_name'], $filename)) { 
     if ($content['options']['ignoreNoFile']) { 
      $this->_files[$file]['received'] = true; 
      $this->_files[$file]['filtered'] = true; 
      continue; 
     } 

     $this->_files[$file]['received'] = false; 
     return false; 
    } 

有没有特殊的机制,这是刚刚超过标准功能

对于直接上传到你的目录,你可以使用类似

$input = fopen("php://input", "r"); 
$file = fopen("/my/directory/filename.eee", "w"); 
while ($data = fread($input, 1024)){ 
    fwrite($file, $data); 
} 
包装

但ZF看起来并不像这样

+0

我认为这可能会有一些包装,但我认为现在普通好的PHP'。 – Tony 2012-03-12 21:12:05