在Zend Framework中覆盖上传的文件

时间:2012-07-02 08:15:12

标签: zend-framework file-upload

如何上传文件,将其移动到目录并在覆盖任何现有文件时保留文件名?在Zend Framework中。

这维护了tmp文件名(如php3382.tmp)

$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('data/');
$adapter->addFilter('Rename', array(
    'target' => 'data/',
    'overwrite' => true
));

$adapter->receive();

并且不会覆盖

$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('data/');
$adapter->receive();

1 个答案:

答案 0 :(得分:1)

试试这个:

...

$adapter->addFilter('Rename', array('overwrite'=> true,
                                    'target'=> sprintf('data/%s', 
                                                       $adapter->getFileName()),
                                    ));
$adapter->receive();

....