这是我的控制器:
<?php
if(!defined('BASEPATH')) exit('no direct access allowed');
class Import_data extends CI_Controller
{
function __construct()
{
parent::__construct();
//$this->load->helper('url');
//$this->load->helper('form');
$this->load->library('upload');
}
function index()
{
}
function image_upload()
{
$config['upload_path'] = './upload';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name'] = 'photo_' . substr(md5(time()), 0, 16);
$image = 'aaa';
$this->upload->initialize($config);
if (!$this->upload->do_upload($image))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);die;
$this->load->view('home_view', $error);
}
else
{
$data = $this->upload->data();
print_r($data);die;
$this->load->view('upload_success', $data);
}
}
}
我尝试打印错误信息,打印出来:
数组([错误] =&gt;您没有选择要上传的文件。)
我不知道我的代码中有什么问题。我正在正确选择文件,这是我的查看代码:
<form name="" method="post" action="<?php echo site_url('import_data/image_upload');?>" enctype="multipart/form-data">
<input type="file" name="excel_file" /> <br/><br/>
<input type="submit" name="submit" value="Submit">
<?php //echo $error;?>
<br/>
<?php //echo $upload_data;?>
</form>
答案 0 :(得分:0)
这是正确的代码。 $这 - &GT; upload-&GT; do_upload( 'excel_file')
必须在此处传递文件输入字段名称。
答案 1 :(得分:0)
传递文件名的位置&#34; excel_file&#34; &GT;&GT;到$ this-&gt; upload-&gt; do_upload(&#39; file_name&#39;);