I'm a new in this forum. I am learning to write an extension !
I'm having problems using an upload class. I tried a lot of the code is still running but no file is up. Does anyone here have any sample code on this issue or can help me see the code below
Code: Select all
private function doc_upload($action = '', $form_name)
{
$old_doc = $this->request->variable('old_doc ', '');
$upload_dir = $this->root_path . 'ext/vtcong/libraries/docs/';
$this->files_upload->reset_vars();
$this->files_upload->set_allowed_extensions(array('doc', 'docx', 'xls', 'xlsx'));
// Upload file
$this->set_file($this->files_upload->handle_upload('files.types.form', $form_name));
echo $form_name;
echo 'Tên file:'.$this->file->get('realname');
$this->file->clean_filename('unique_ext');
echo $this->file->get('realname');
$name = $this->file->get('realname');
if ($action == 'edit_article' && empty($name))
{
return $old_doc;
}
if (!$this->file->move_file($upload_dir))
{
$this->file->set_error('FILE_MOVE_UNSUCCESSFUL');
}
if (count($this->file->error))
{
throw new \phpbb\exception\runtime_exception($this->file->error[0]);
}
// remove the old doc if set
@unlink($this->root_path . 'ext/vtcong/libraries/docs'. $old_doc);
return $this->file->get('realname');
}