我是CodeIgniter的新手
我已经看过并尝试了几个类似于这个问题的答案。但仍然显示相同的错误。
这是我的观点
<?php
echo form_open_multipart('halaman_admin/tambah_gambar');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
我的控制器
$config['upload_path'] = './assets/media/gambar/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '5000';
$config['max_width'] = '2024';
$config['max_height'] = '1468';
$this->load->library('upload', $config);
$this->load->helper('form');
$this->load->helper('url');
$this->load->model('admin_model');
$data['pesan'] = '';
if(!$this->upload->do_upload())
{
if(isset($_POST['upload']))
$data['pesan'] = $this->upload->display_errors();
}
else
{
$data['upload_data'] = $this->upload->data();
$data['pesan'] = 'SUKSES';
$config_resize = array(
'source_image' => $data['upload_data']['full_path'],
'new_image' => './assets/media/thumb/',
'maintain_ration' => true,
'width' => 160,
'height' => 120
);
$this->load->library('image_lib', $config_resize);
if(! $this->image_lib->resize())
{
$data['pesan'] = $this->image_lib->display_errors();
}
}
$data['images'] = $this->admin_model->fetch_image(FCPATH.'assets/media/gambar');
$this->load->view('view_admin/upload_gambar_view', $data);
我的模特
function fetch_image($path)
{
$this->load->helper('file');
return get_filenames($path);
}
有什么可以帮助我吗?
因为我已经尝试了一些我发现的关于此错误的内容,它仍然会上传错误并显示&#34;您没有选择要上传的文件。&#34;
感谢您的帮助
答案 0 :(得分:0)
必须提及输入字段的名称
查看:
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<input type="submit" value="upload" />
控制器:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
//upload is failure
}
else
{
//upload is success
}
}
}
?>
答案 1 :(得分:0)
我找到了它:)
我正在使用jquery mobile,所以当我添加数据-ajax =“false”时,我的代码工作正常 起初我以为php中有错误,所以我提出这个问题,结果发现使用jquery-mobile multipart有特殊要求
感谢您的帮助:)