我正在尝试将 2 个变量传递给表单页面。
第一个是对表单字段的查询,第二个是错误变量。
加载页面时,出现以下错误:
遇到 PHP 错误
严重性:通知
消息:未定义变量:错误
文件名:views/upload_form.php
行号:7
这是我的控制器:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->database();
}
function index()
{
$this->load->helper('url');
$this->load->model('Image_model');
$data['query'] = $this->Image_model->image_biz();
$this->load->view('upload_form', $data, array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = dirname($_SERVER["SCRIPT_FILENAME"]).'/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$image_data = array('upload_data' => $this->upload->data());
// can be add extra feature here.
$insert_data = array(
'image_file' => $image_data['upload_data']['file_name'],
'image_path' => $image_data['upload_data']['full_path'],
'image_ext' => $image_data['upload_data']['file_ext'],
'image_width'=> $image_data['upload_data']['image_width'],
'image_height' => $image_data['upload_data']['image_height'],
);
$this->db->insert('image', $insert_data);//load array to database
$this->load->view('upload_success', $image_data);
}
}
}
?>
这是我的视图页面“upload.php”:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
Image: <input type="file" name="userfile" size="20" /><br>
<label for="select">Business ID:</label>
<select name="image_bizID">
<?php foreach ($query->result() as $row) { ?>
<option value=""><?=$row->biz_id;?></option>
<?php } ?>
</select>
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
任何帮助解决此错误将不胜感激。
谢谢你。