0

我是 CodeIgniter 的新手

我已经看过并尝试了一些与此问题类似的答案。但仍然显示相同的错误。

这是我的观点

<?php 
  echo form_open_multipart('halaman_admin/tambah_gambar');
  echo form_upload('userfile');
  echo form_submit('upload', 'Upload');
  echo form_close();
?>

我的控制器

    $config['upload_path'] = './assets/media/gambar/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = '5000';
    $config['max_width'] = '2024';
    $config['max_height'] = '1468';

    $this->load->library('upload', $config);
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->model('admin_model');
    $data['pesan'] = '';

    if(!$this->upload->do_upload())
    {
        if(isset($_POST['upload']))
            $data['pesan'] = $this->upload->display_errors();
    }
    else
    {
        $data['upload_data'] = $this->upload->data();
        $data['pesan'] = 'SUKSES';

        $config_resize = array(
            'source_image'  => $data['upload_data']['full_path'],
            'new_image'     => './assets/media/thumb/',
            'maintain_ration' => true,
            'width'         => 160,
            'height'        => 120
            );

        $this->load->library('image_lib', $config_resize);
        if(! $this->image_lib->resize())
        {
            $data['pesan'] = $this->image_lib->display_errors();
        }
    }

    $data['images'] = $this->admin_model->fetch_image(FCPATH.'assets/media/gambar');
    $this->load->view('view_admin/upload_gambar_view', $data);

我的模型

function fetch_image($path)
{
    $this->load->helper('file');
    return get_filenames($path);
}

有什么可以帮助我的吗?

因为我已经尝试了一些关于此错误的发现,它仍然上传错误并显示“您没有选择要上传的文件”。

谢谢你的帮助

4

2 回答 2

0

我找到了 :)

我使用的是jquery mobile,所以当我添加data-ajax =“false”时,我的代码工作正常起初我以为php有错误,所以我提出这个问题,原来使用有特殊要求jquery-移动多部分

谢谢你的帮助 :)

于 2015-03-30T13:32:53.547 回答
0

不得不提输入字段的名字

看法 :

<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<input type="submit" value="upload" />

控制器 :

<?php
class Upload extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }       

    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);        

        if ( ! $this->upload->do_upload('userfile'))
        {
            //upload is failure
        }
        else
        {
            //upload is success
        }
    }
}
?>
于 2015-03-30T09:11:22.550 回答