我正在使用两个安装代码,一个用于前端,一个用于管理面板。我正在尝试将文件从管理面板上传到前端面板。
结构就像这样
abc.com
-root installtion for front end
-images
-logos
-admin
-another installation for admin panel
现在我的代码就是这个
$config = array(
'upload_path' => 'home/username/public_html/abc.com/images/logos/',
'allowed_types' => 'gif|jpg|png|PNG',
'file_name' => $file_name,
'max_width' => '1024',
'max_height' => '768',
'encrypt_name' => true,
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
$upload_data = $this->upload->data();
if(!$upload_data)
{
$this->upload->display_errors('<p>', '</p>');
die();
}
但文件没有上传,我没有收到任何错误。
答案 0 :(得分:1)
你忘了$this->upload->do_upload()
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
编辑01
试试这个
$file_name = 'my_file';
$config = array(
'upload_path' => 'home/username/public_html/abc.com/images/logos/',
'allowed_types' => 'gif|jpg|png|PNG',
'file_name' => $file_name,
'max_width' => '1024',
'max_height' => '768',
'encrypt_name' => true,
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}