젠드 프레임 워크 업로드 한 이미지의 이름을 변경할 수 없습니다 형태 I은 다음의 한다음 I 컨트롤러 코드가
$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));
}
}
를 I가 업로드 한 이미지의 이름을 변경하고 있으므로을 to $ company_name.png 그 이유는 컨트롤러에서 addFilter 메소드를 사용하는 이유입니다. $ company_name은 사용자가 입력 한 textfield company (양식) 값입니다.하지만 이름은 변경되지 않았습니다. 이름을 변경하려면 수행해야하는 작업은 무엇입니까 ??
내 경우에 $ location과 $ yourLocation은 동일한 경로를 이미 지정 했으므로 동일하지만 위의 코드 작성 후 이미지는 이름이 변경되지 않았습니다. – ryan
이는 move_uploaded_file이 false를 반환 함을 의미합니다. 여기에서 $ location은 "C : \ Users \ 398853 \ Documents \ NetBeansProjects \ MST \ public/images \ Chrysanthemum.jpg"이며 $ yourLocation. $ company_name. '.jpg' Users \ 398853 \ Documents \ NetBeansProjects \ MST \ public/images/jhm.jpg " – ryan
그냥'rename() '을 사용해 보셨나요? – dinopmi