Php 使用验证更新codeigniter上的图像
我被困在这个项目上了。我已经想了一个星期了。我总是在更新图像时出错。我希望你能帮助我 代码如下: 控制器:Php 使用验证更新codeigniter上的图像,php,codeigniter,Php,Codeigniter,我被困在这个项目上了。我已经想了一个星期了。我总是在更新图像时出错。我希望你能帮助我 代码如下: 控制器: function update_post(){ $this->load->model('membership_model'); $this->membership_model->update_post(); } 型号 function update_post(){ $config['upload_path']
function update_post(){
$this->load->model('membership_model');
$this->membership_model->update_post();
}
型号
function update_post(){
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$data['error'] = array('error' => $this->upload->display_errors());
$post_id = $this->uri->segment(3);
$data['result'] = $this->db->query("SELECT * FROM post WHERE post_id=$post_id");
$this->load->view('template/member-header');
$this->load->view('edit_post',$data);
$this->load->view('template/footer');
}
else
{
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
//resize
$config['image_library'] = 'gd2';
$config['source_image'] = './upload/'.$file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = true;
$config['width'] = 250;
$config['height'] = 200;
$config['new_image'] = './upload/'.$file_name;
$this->load->library('image_lib',$config);
$this->image_lib->resize();
//resize
$data = array(
'post_title' => htmlentities($this->input->post('title')),
'post_content' => htmlentities($this->input->post('content')),
'post_image' => $file_name
);
$this->db->update('post', $data);
$this->load->view('template/member-header');
$this->load->view('edit_success');
$this->load->view('template/footer');
}
}
查看
<?php
if(isset($error)){
echo "<span class='red'>".$error."</span>";
}
else{
}
?>
<?php
$post_id = $this->uri->segment(3);
// get single data on database
if ($result->num_rows() > 0){
$row = $result->row();
$image_path = base_url('upload/'.$row->post_image);
echo "<br /><br /><center><img src='$image_path' border='5'/></center>";
$title = $row->post_title;
$content = $row->post_content;
echo form_open_multipart('site/update_post/'.$post_id);
echo "<li><h4>Image:</h4> ".form_upload('userfile','','required')."</li>";
echo "<li><h4>Title:</h4> ".form_input('title',$title,'required')."</li>";
echo "<li><h4>Content:</h4> ".form_textarea('content',$content,'required')."</li>";
echo "<li>".form_submit('submit','Post').form_reset('reset','Reset')."</li>";
echo form_close();
}
?>
基于您的错误注释。见: 具有单个结果的标准查询
$result = $this->db->query("YOUR QUERY");
$row = $result->row();
echo $row->post_title;
具有多个结果的标准查询
$result = $this->db->query("YOUR QUERY");
if ($result->num_rows() > 0)
{
foreach ($result->result() as $row)
{
echo $row->post_title;
echo $row->post_content;
}
}
在$this->upload->do_upload()中输入文件名。像$this->upload->do_upload('myDoc')这里是我得到的错误遇到的PHP错误严重性:注意消息:数组到字符串转换文件名:views/edit_post.PHP行号:9