[英]Image uploading doesn't work in codeigniter
这是我的控制器:
<?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);
}
}
}
我试图打印以下错误消息:
数组([错误] =>您没有选择要上传的文件。)
我不知道我的代码有什么问题。 我正在正确选择文件,这是我的查看代码:
<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>
这是正确的代码。 $ this-> upload-> do_upload('excel_file')
文件输入字段名称必须在此处传递。
您将文件名“ excel_file” >>传递给$ this-> upload-> do_upload('file_name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.