をアップロードされた画像の名前を変更することができません:次のようにIは、コントローラコードを有するZendのフレームワーク内
$form_company=new Project_Form_AddCompany();
$this->view->form=$form_company;
$form_company->setAction('add-Company');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form_company->isValid($formData)) {
$company_name = $this->_getParam('company', 0);
echo $company_name;
// success - do something with the uploaded file
$uploadedData = $form_company->getValues();
$form_company->uploaded_file->addFilter(new Zend_Filter_File_Rename(array('target' => $company_name.'.jpg')));
Zend_Debug::dump($uploadedData, '$uploadedData');
//echo 'End: ';
}
// action body
}
形で私は次のコードたが:私がアップロードした画像の名前を変更する必要があるので
<?php
class Project_Form_AddCompany extends Zend_Form
{
public function init()
{
$company=new Zend_Form_Element_Text('company');
$company->setLabel('CompanyName')
->setRequired(true);
$com_des=new Zend_Form_Element_Textarea('com_des');
$com_des->setLabel('CompanyDescription')
->setAttrib('cols', '40')
->setAttrib('rows', '4')
->setAttrib('style', 'resize: none;')
->setRequired(true)
->addValidator('NotEmpty');
$com_addr=new Zend_Form_Element_Textarea('com_addr');
$com_addr->setLabel('CompanyAddress')
->setAttrib('cols', '40')
->setAttrib('rows', '4')
->setAttrib('style', 'resize: none;')
->setRequired(true)
->addValidator('NotEmpty');
$file = new Zend_Form_Element_File('uploaded_file');
$file->setDestination(PUBLIC_PATH . '/images/')
->setLabel('File')
->setRequired(true)
->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($company,$com_des,$com_addr,$file,$submit));
}
}
を〜$ company_name.png thats私はコントローラのaddFilterメソッドを使用している理由は、$ company_nameはuser.Butの名前で入力されたtextfield company(フォーム)の値です。名前は変更されていません。
私の場合、$ locationと$ yourLocationは同じ形式でパスを指定しているので同じですが、ここに書いた後にコードイメージの名前は変更されませんでした。 – ryan
これは、move_uploaded_fileがfalseを返していることを意味します。ここで、$ locationは "C:\ Users \ 398853 \ Documents \ NetBeansProjects \ MST \ public/images \ Chrysanthemum.jpg" Users \ 398853 \ Documents \ NetBeansProjects \ MST \ public/images/jhm.jpg " – ryan
あなたは' rename() 'を使ってみましたか? – dinopmi