0

我正在尝试设置一个站点,以便我可以使用 Code Igniter(CI) 中的 Web 表单上传图像。我没有收到任何错误,但文件也没有被保存。我想知道那些成功上传图片的人是否可以帮助解释可能是什么问题?

View:
<?php
    echo form_open_multipart('admin/galleryUpload') . "\n";
    echo "<div class='span-8'><span class='text'>Image:</span>" . form_upload('uploadImg') . "</div>";
    foreach ($gallery as $picture)
    {
        $order[] = $picture->order;
    }
    $order[] = count($order) + 1;
    echo "<div class='span-6 last'><span>Image Order #:</span>" . form_dropdown('order', $order) . "</div><div class='span-14'>&nbsp;</div>";
    $conf = array('name' => 'alt_text', 'size' => '75');
    echo "<div class='span-14 last'><span>Discription:</span>" . form_input($conf) . "<br /></div>";
    echo form_hidden('propertyID', "$propertyID");
    echo form_submit('upload', 'Upload');
    echo form_close();
?>

Controller:
class Admin extends Controller
{
    function galleryUpload()
    {
        if (! $this->session->userdata('is_admin'))
        {
            redirect('admin/index');
        }
        else
        {
            $this->load->model('admin_model');
            $this->admin_model->imgUpload();
        }
    }
}

Model:
class Admin_model extends Model
{
    function imgUpload()
    {
        $id = $this->input->post('propertyID');
        $order = $this->input->post('order');
        $alt_text = $this->input->post('alt_text');

        $config = array(
                'allowed_types' => 'jpg|jpeg|gif|png',
                //'upload_path' => '../' . $this->imgPath($id),
                'upload_path' => '../img/galleries/temp/',
                'max_size' => '5000', // 5MB files max
                );

        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        $config = array(
                'source_image' => $image_data['full_path'],
                'new_image' => $this->imgPath($id) . '/thumbs',
                'maintain_ratio' => TRUE,
                'width' => '60'
                );
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
    }
}
4

1 回答 1

1

用户指南

默认情况下,上传例程期望文件来自名为 userfile 的表单字段,并且表单必须是多部分类型

因此,您要么必须将表单字段的名称更改为userfile

form_upload('userfile')

将表单字段的名称传递给do_upload

$this->upload->do_upload('uploadImg');
于 2012-09-05T23:06:23.817 回答