2010-03-17 88 views
0

代碼說Zend_Form_element_File :: setDestination()已棄用並使用重命名過濾器。然而,重命名過濾器當前的代碼是這樣的,當設置路徑時,只給出臨時名稱。原始文件名丟失。ZendFramework Zend_Form_Element_File setDestination與重命名過濾器

<?php 
$file = new Zend_Form_Element_File(); 
$file->setDestination('/var/www/project/public'); 
?> 

VS

<?php 
$file = new Zend_Form_Element_File(); 
$file->addFilter('Rename', array('target' => '/var/www/project/public')); 
?> 

的任何解決方案,上傳文件,以便保留原始文件名結構,但檢查現有的文件和追加_1.ext或_2.ext?

回答

0

提交表格後,你可以檢查$_FILES['file_element']['name']檢查現有的文件,然後調用之前設置你的表單元素上的重命名過濾器:

$form->getValues()/isValid() or $form->file_element->receive()

1

您需要在上傳後查詢文件的名稱,然後再添加重命名過濾器。例如:

if ($form->file->isUploaded()) { 
    $fileinfo = $form->file->getFileInfo(); 
    $filename = $fileinfo['file']['name']; 
    $extn = pathinfo($filename,PATHINFO_EXTENSION); 
    $uploadname = $this->_makeFilename($formData, $extn); 
    $uploadfilepath = UPLOADED_FILES_PATH . '/' . $uploadname; 
    $form->file->addFilter('Rename', $uploadfilepath); 
    $receiveStatus = $form->file->receive(); 
}