我花了几天的时间试图使上传的图像文件显示在其文件夹中,但是当我上传图像文件时,它进入了数据库,但没有显示在文件夹中,我不知道为什么。
public function additems()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 106660;
$config['max_width'] = 1026664;
$config['max_height'] = 76668;
$this->load->library('upload', $config);
$this->load->view('templates/dashboard_head.php');
$this->load->view('admin/create_product');
$this->load->view('templates/admin_sidebar');
$this->load->view('templates/admin_footer');
$this->load->library('upload', $config);
if($this->input->post('submit'))
{
//get form's data and store in local varable
$name=$this->input->post('name');
$price=$this->input->post('price');
$description=$this->input->post('discription');
$code = $this->input->post('code');
$data = array('upload_data' => $this->upload->data());
$image = $_FILES['image']['name'];
//call saverecords method of Hello_Model and pass variables as parameter
$this->admin->insert_products($name, $price, $description,$code,$image);
echo "<script>
window.alert('added succesfully');
</script>";
}
答案 0 :(得分:0)
图像在上传时被分配了一个临时名称。您必须使用以下方式移动它:
$uploadDirectory = './uploads';
move_uploaded_file( $_FILES['image']['tmp_name'], $uploadDirectory );