0
我试图用rename-addFilter重命名上传的文件。实际上传已经有效,但文件只是上传而不是重命名,所以我该怎么做? 这里是我的控制器代码,上传文件:Zend_File_Transfer:上传后重命名文件
//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();
我想你可能会收到文件你应用滤镜之前。如果您针对表单调用getValues(),它将接收文件。 ** from引用:** _Per默认情况下,当您调用表单上的getValues()时,将自动接收文件。这种行为背后的原因是,文件本身就是文件元素的值。因此:** _Still,有时您可能需要在不接收文件的情况下调用getValues()。您可以通过调用setValueDisabled(true)来对其进行归档。要获得这个标志的实际价值,你可以调用isValueDisabled()._我希望这可以帮助... – RockyFord
我认为,这将帮助我在未来。 不幸的是,我需要表格的数据,因为我使用一个控制器进行多次编辑。这个表单的属性'type'调用了添加或者更新数据库所需要的动作,或者在这个例子中是一个文件。 但正如你在我自己的答案中看到的那样:PHP非常简单并且完美地工作。那为什么要关心? – StoryTeller