正確上傳我試圖上傳的圖像,但只有內容插入到數據庫中正確但圖像路徑或文件不上載這裏我的代碼,圖像不是笨
我的觀點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