在cakephp中,我想在表单条目上上传文件,例如一个简历上传,并形成人们姓名,地址等的输入。问题是,当我上传文件后,我收到文件上传后“未选择文件”。该功能有效,但这条消息让用户感到困惑,因为我想要显示文件的名称,而不是“没有选择文件”。
EDIT 在“浏览”按钮旁边,标签显示“未选择文件”。如何禁止/更改此消息?
更新:找到一个可能不是最佳解决方案的变通方法答案。
echo $this->Form->input('reason', array('label' => 'Reason for Cancellation', 'style'=> "width:30%",'value'=>$reason));
echo __('Upload Attachment');
echo $this->Form->input('resume_file', array('type' => 'file'));
echo $this->Form->submit('Upload', array('name'=>'upload'));
echo $this->Form->end();
public function uploadfile() {
$reason=null;
if ($this->request->is('post')) {
if (isset($this->request->data['upload'])) {
$reason=$this->request->data['Resume']['reason'];
if ($this->attachmentupload() && $this->Resume->save($this->request->data)) {
$this->Session->setFlash(__('The attachment has been saved'), 'flash_success');
} else {
$this->Session->setFlash(__('The attachment could not be saved. Please, try again.'),'flash_alert');
}
}
}
}
public function attachmentupload() {
$file = $this->request->data['Resume']['resume_file'];
$resume_org_filename = $file['name'];
$resume_filename = $file['name'];
if ($file['error'] === UPLOAD_ERR_OK) {
// Code to check if file with the same name exists. If it exists - add n towards the end
$t = 0;
$url = APP.'Resumes'.DS.$resume_filename;
while(file_exists($url)) {
$resume_filename = substr($resume_filename,0, strpos($resume_filename, '.'))."_$t".strstr($resume_filename, '.');
$url = APP.'Resumes'.DS.$resume_filename;
$t++;
}
// Set the parameters
if (move_uploaded_file($file['tmp_name'], $url)) {
$this->request->data['Resume']['tutor_id'] = -1;
$this->request->data['Resume']['student_id'] = -1;
$this->request->data['Resume']['url'] = $url ;
$this->request->data['Resume']['resume_filename'] = $resume_filename;
$this->request->data['Resume']['resume_org_filename'] = $resume_org_filename;
return true;
}
}
return false;
}
答案 0 :(得分:0)
答案是禁止标签并在带有标签的表/ div中添加元素