正确上传我试图上传的图像,但只有内容插入到数据库中正确但图像路径或文件不上载这里我的代码,图像不是笨
我的观点post.php中文件代码:
<form action="" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Book Title</td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td>Book Author</td>
<td><input type="text" name="author" /></td>
</tr>
<tr>
<td>Book Image</td>
<td><input type="file" name="image" /></td>
</tr>
<tr>
<td>Book Description</td>
<td><input type="text" name="content" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" /></td>
</tr>
</table>
</form>
这里我控制器的welcome.php文件代码:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
if (!empty($_POST)) {
$title = $this->input->post('title');
$author = $this->input->post('author');
$image['upload_path'] = './images/'.$_FILES['image']['tmp_name'];
$image['allowed_types'] = 'gif|jpg|png';
$image['max_size'] = '200';
$image['max_width'] = '2000';
$image['max_height'] = '1500';
$this->load->library('upload', $image);
$content = $this->input->post('content');
$date = date('Y-m-d');
if ($title && $author && $image && $content) {
$this->load->model('insert');
$data = array(
//field list
'book_title' => $title,
'book_author' => $author,
'book_image' => $image['upload_path'],
'book_content' => $content,
'date' => $date
);
$id = $this->insert->form($data);
}
}
$this->load->view('insert/post');
}
}
请确保您的根目录和.htacess文件中有'images',以允许访问images文件夹。 – Himanshu