我正在使用 CodeIgniter 文件上传类。
我无法将错误数组加载到文件上传表单视图中。(这将返回“未定义变量:错误”消息或“数组到字符串转换”错误消息)
而且我也无法将upload_data 数组加载到成功视图中。(这将返回“数组到字符串转换”错误消息。)
这是我的控制器 - upload.php
<?php
class Upload extends Admin_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->helper('directory');
}
function index()
{
$this->data['subview'] = 'admin/upload_form';
$this->load->view('admin/_layout_main', $this->data);
}
function do_upload()
{
$this->load->library('upload');
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->data['error'] = $error;
$this->data['subview'] = 'admin/upload_form';
$this->load->view('admin/_layout_main', $this->data);
}
else
{
$upload_data = array('upload_data' => $this->upload->data());
$this->data['upload_data'] = $upload_data;
$this->data['subview'] = 'admin/upload_success' ;
$this->load->view('admin/_layout_main', $this->data);
}
}
}
?>
这是上传表单视图upload_form.php
<?php echo $error;?>
<?php echo form_open_multipart('admin/upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
这是成功页面视图
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('admin/upload', 'Upload Another File!'); ?></p>