zend中重命名文件后文件上传
这是我的表单
class Admin_Form_RoomtypeForm extends Zend_Form
{
public function init()
{
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name :');
$imagePath = '/home/dinuka/image';
$image = new Zend_Form_Element_File('image');
$image->setLabel('Image URL :');
$image->setDestination($imagePath);
$image->addValidators(array(array('IsImage', false)));
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($name, $image, $submit));
}
}
这是我的控制器
class Admin_RoomtypesController extends Zend_Controller_Action
{
public function addAction()
{
$form = new Admin_Form_RoomtypeForm();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
$form->populate($formData);
$name = $form->getValue('name');
}
}
}
现在我想在将文件名更改为 $name 值后上传文件。我该怎么做?
This is my form
class Admin_Form_RoomtypeForm extends Zend_Form
{
public function init()
{
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name :');
$imagePath = '/home/dinuka/image';
$image = new Zend_Form_Element_File('image');
$image->setLabel('Image URL :');
$image->setDestination($imagePath);
$image->addValidators(array(array('IsImage', false)));
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($name, $image, $submit));
}
}
This is my controller
class Admin_RoomtypesController extends Zend_Controller_Action
{
public function addAction()
{
$form = new Admin_Form_RoomtypeForm();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
$form->populate($formData);
$name = $form->getValue('name');
}
}
}
Now i want to upload file after change file name as $name value. How can i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须为我的一个项目做这样的事情,除了我需要唯一的文件名。这不是一个完美的解决方案,但它可能会让您走上正轨:
I had to do something like this for one of my projects, except i needed unique filenames. This isn't a perfect solution, but it may put you on the right track:
最后我做了如下。
-Form -
-Controller -
默认图像上传到/tmp 文件夹。作为我的示例,我们可以使用
setDestination()
方法更改它。感谢大家
Finally I done it as following.
-Form -
-Controller -
default image is upload to /tmp folder. We can change it using
setDestination()
method as my example.Thank for All