![](/img/trans.png)
[英]Codeigniter uploading an image to a path folder but in the no record in the database
[英]Image Path not uploading into database php codeigniter
我正在嘗試使用帶有圖像的產品信息構建一個項目。 我嘗試了下面給出的一些代碼,但我無法在數據庫中上傳圖像路徑。 我是一個試圖學習代碼的新手。
controller 代碼:-
class Category extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('Category_model');
}
private function do_upload(){
$config['upload_path']='./uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('product_image')){
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/pages/add_product_form', $error);
}
else
{
$upload_data = $this->upload->data();
$this->Category_model->insert_data( $upload_data['upload_path']);
}
$data = array('upload_data' => $this->upload->data());
}
function save_product(){
$this->do_upload();
$this->session->set_userdata('message','Product saved successfully');
$this->add_product();
}
}
Model 代碼:-
function insert_data( $path_name){
$data = array(
'product_image' => $path_name
);
$data['product_status']=1;
$this->db->insert('tbl_product', $data);
}
查看代碼:-
<form class="form-horizontal" action="<?php echo base_url()?>index.php/Category/save_product" enctype="multipart/form-data" method="post">
<fieldset>
<div class="control-group">
<label class="control-label" for="typeahead">Product Name </label>
<div class="controls">
<input type="text" name="product_name" class="span6 typeahead" id="typeahead" data-provide="typeahead" data-items="4" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="selectError3">Product Category</label>
<div class="controls">
<select name="product_category" id="selectError3">
<option>Select Category</option>
<?php foreach($category_info as $category){ ?>
<option value="<?php echo $category->category_id ?>"><?php echo $category->category_name; ?></option>
<?php } ?>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="typeahead">Product Image </label>
<div class="controls">
<input name="product_image" type="file" name="fileToUpload" id="fileToUpload">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="reset" class="btn">Cancel</button>
</div>
</fieldset>
</form>
這是我上面給出的代碼,但仍然沒有獲取數據庫中的圖像路徑,請在這方面提供幫助。在此先感謝。
只是增加了 max_size,max_width,max_height 就解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.