0

我尝试使用 PHP 将大图像 (>~1.5MB) 上传到我的网站,但文件没有出现在服务器上。有时我会收到错误 1(超出最大尺寸)。

有什么我可以做的吗?

public function do_upload($field) {
    $config['upload_path'] = './uploads/';
    $config['max_size'] = '100000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';

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

    if (!$this->upload->do_upload($field)) {
        $error = array('error' => $this->upload->display_errors());

        return $error;
    } else {
        /*$data = array('upload_data' => $this->upload->data());
        return $data;*/
        $updata =$this->upload->data();
        $data = $updata['raw_name'].$updata['file_ext'];
        return $data;
    }
}

我可以在这里调用函数:

$pic = $this->do_upload('inputUpProfile');

这里我将图片保存到数据库中:

        if ($this->input->post('post') == ''){
            $type="image";
        } else {
            $type="image-with-text";
        }
    } else {
        $pic = ""; 
        $type = "text"; 
    }

    $result = $this->blog->addPost($_SESSION['user_id'], $type  , $this->input->post('post'),$pic);
}

楷模:

function addPost($user_id, $post_type, $post , $pic ) {
    $today = date("Y-m-d H:i:s");
    $vales = array('ev_user_id' => $user_id, 'ev_type' => $post_type, 'ev_text' => $post,'ev_pic' => $pic, 'ev_date' => $today);
    $this->db->insert($this->table_name, $vales);
}

错误:

错误号:1054

“字段列表”中的未知列“数组”

插入events( ev_user_id, ev_type, ev_text, ev_pic, ev_date) 值 (1, 'image', '', Array, '2013-10-02 23:32:50')

4

2 回答 2

0

错误不言自明:第四个值 ( Array) 是错误的。我想您想将文件名存储在数据库中。

根据CodeIgniter 文档,您的$pic变量有一个方法,该方法data()返回一个包含以下字段的数组:

Array
(
    [file_name]    => mypic.jpg
    [file_type]    => image/jpeg
    [file_path]    => /path/to/your/upload/
    [full_path]    => /path/to/your/upload/jpg.jpg
    [raw_name]     => mypic
    [orig_name]    => mypic.jpg
    [client_name]  => mypic.jpg
    [file_ext]     => .jpg
    [file_size]    => 22.2
    [is_image]     => 1
    [image_width]  => 800
    [image_height] => 600
    [image_type]   => jpeg
    [image_size_str] => width="800" height="200"
)
于 2013-10-02T20:57:17.447 回答
0

您对 $pic 定义有疑问,它有两个定义。

改变这个:

function addPost($user_id, $post_type, $post , $pic ) {
    $today = date("Y-m-d H:i:s");
    $vales = array('ev_user_id' => $user_id, 'ev_type' => $post_type, 'ev_text' => $post,'ev_pic' => $pic, 'ev_date' => $today);
    $this->db->insert($this->table_name, $vales);
}

对此:

function addPost($user_id, $post_type, $post , $ev_pic ) {
    $today = date("Y-m-d H:i:s");
    $vales = array('ev_user_id' => $user_id, 'ev_type' => $post_type, 'ev_text' => $post,'ev_pic' => $ev_pic, 'ev_date' => $today);
    $this->db->insert($this->table_name, $vales);
}

注意$pic$ev_pic的变化。

错误在于将此调用的结果用作数据库中的 pic 值:

$pic = $this->do_upload('inputUpProfile');
于 2013-10-02T20:58:06.750 回答