我正在尝试使用rename-addFilter重命名上传的文件。实际上传已经有效,但文件只是上传而不是重命名,所以我该怎么办呢? 这是我的控制器代码,它上传文件:
//Getting the new filename, works perfectly:
$name = explode('.', $form['pic']);
$ext = $name[1];
$mapper = new Application_Model_CmsMap();
$row = $mapper->fetchRow('childId = "' . $id . '" AND type= "pic"');
$new_filename = $row->name.'.'.$ext;
//All images will and are be stored in /public/images/
//Maybe the picture should be replaced, so it should be overwrited, in case it already exists
$upload->addFilter('Rename', array(
'target' => '/images/'.$new_filename,
'overwrite' => true,
)
);
$upload->receive();
答案 0 :(得分:2)
螺丝Zend。 好的'PHP很简单,效果很好:
rename('images/'.$form['pic'], 'images/'.$new_filename);
答案 1 :(得分:0)
应该工作: - )
$transferAdapter = new Zend_File_Transfer_Adapter_Http();
$transferAdapter->receive();
$newFilename = 'MY_NEW_FILE';
$filterFileRename = new Zend_Filter_File_Rename(array(
'target' => 'PATH' + $newFilename,
));
$file = $transferAdapter->getFileName();
// new location and name..
$movedFile = $filterFileRename->filter($file);