0
我試圖在上傳圖片時上傳路徑。將img路徑上傳到db codeigniter
當我向底部註釋模型時,表格當前將文件發送到文件系統,沒有任何問題。
控制器:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index() {
$this->load->view('uploaderview', array('error' => ' '));
}
function do_upload(){
$config['upload_path'] = './upl0d/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048'; //2mb
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
if (! $this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('uploaderview', $error);
} else {
## Insert into filesystem.
$data = array('upload_data' => $this->upload->data());
## load the success page.
$this->load->view('uploadsuccess', $data);
## Insert into db
## then insert the img name into the database
this->load->model('uploadermodel');
$this->uploadermodel->uploadcoupon();
}
}
}
和模型:
<?php
class Uploadermodel extends CI_Model{
function __construct(){
// Call the Model constructor
parent::__construct();
}
function uploadcoupon(){
$uploadFileName = $upload_data['orig_name'];
$currentDt = date('Y-m-d H:i:s');
$data = array('fileNameUploaded'=>$uploadFileName,'date'=>$currentDt);
$this->db->insert('Coupon', $data);
}
}
?>
當我包括模型,我收到以下錯誤:
syntax error, unexpected T_OBJECT_OPERATOR on line 36
這裏控制器的第36行:
this->load->model('uploadermodel');
有沒有人看到我在做什麼錯在這裏?
' $ this' -------- –
愚蠢的我。謝謝佩卡 – CodeTalk
問題是變量$ uploadFileName爲空或空。我該如何解決? – CodeTalk