我尝试使用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
'字段列表'中的未知列'数组'
INSERT INTO
events
(ev_user_id
,ev_type
,ev_text
,ev_pic
,ev_date
)VALUES(1,'image','',Array,'2013-10-02 23:32:50')
答案 0 :(得分:0)
错误不言而喻:第四个值(Array
)是错误的。我想你想把文件名存储在数据库中。
根据CodeIgniter documentation您的$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"
)
答案 1 :(得分: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');