【发布时间】:2013-02-03 19:29:59
【问题描述】:
我正在尝试上传已上传图片的路径。
当我在底部注释掉模型时,表单当前将文件发送到文件系统没有问题。
控制器:
<?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');
有人看到我在这里做错了吗?
【问题讨论】:
-
我真傻。谢谢佩卡
-
问题是变量 $uploadFileName 为 null 或为空。我该如何解决这个问题?
-
$upload_data应该来自哪里?您没有从其他函数传递它 -
如果您查看:ellislab.com/codeigniter/user-guide/libraries/… 它在那里使用它。应该传入哪个函数
标签: php codeigniter file-upload