当我使用表单将文件上传到服务器时,操作失败。但是,我无法显示错误消息,因为没有传递错误。
两个控制器功能
public function update_image()
{
$data['page'] = 'Profiilikuva';
$this->load->view('templates/header', $data);
$this->load->view('templates/user/navbar', $data);
$this->load->view('pages/user/upload_image', $data);
$this->load->view('templates/footer', $data);
}
public function upload_image()
{
$data['breakpoint'] = 'Alku';
$data['page'] = 'Profiilikuva';
$config['upload_path'] = './images/profile';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$data['breakpoint'] = 'Kirjasto';
$this->load->view('templates/header', $data);
$data['breakpoint'] = 'Navigointi Alku';
$this->load->view('templates/student/navbar', $data);
$data['breakpoint'] = 'Navigointi Valmis';
if ( $this->upload->do_upload('profileimage') )
{
$data['breakpoint'] = 'Latausvirhe';
$data['db_error'] = 'Ei Virheitä';
$data['file_error'] = $this->upload->display_errors();
$this->load->view('pages/error', $data);
}
else
{
$data['breakpoint'] = 'Lataussuoritettu';
$where = array('userid' => $this->session->user->userdata->userid);
$values = array(
'profileimage' => $this->upload->data('file_name')
);
if($this->user->update($where, $values) )
{
$this->load->view('pages/user/success');
}
else
{
$data['breakpoint'] = 'Tietokanta';
$e = $this->db->error();
$data['db_error'] = $e['message'];
$data['file_error'] = $this->upload->display_errors();
$this->load->view('pages/error');
}
}
$data['breakpoint'] = 'Loppu';
$this->load->view('templates/footer');
}
现在,错误页面本身如下所示:
<div id="main">
<div class="content">¨
<h2> Tapahtui virhe.</h2>
<p>
Virheen tiedot ovat alla. Jos virhe toistuu, ota yhteyttä ylläpitoon. <?php echo $breakpoint; ?> <br />
</p>
<p>
<h3>Tietokanta virheet:</h3>
<?php echo $db_error; ?>
</p>
<p>
<h3>Tiedostovirheet</h3>
<?php echo $file_error; ?>
</p>
<p>
<a class="action" href="<?php echo base_url('Userpanel');?>">Palaa profiilin</a> <br />
</p>
</div>
</div>
和表单本身:
<div id="main">
<div class="content">
<h2>Lataa profiilikuva</h2>
<p>
<?php echo form_error(); ?>
</p>
<p>
<?php
echo form_open_multipart('Userpanel/upload_image');
echo form_fieldset('Kuva');
echo form_upload('profileimage');
echo form_fieldset_close();
echo form_close();?>
</div>
<div class="controls">
<a class="action" href="<?php echo base_url('Userpanel');?>">Peruuta</a> <br />
</div>
</div>
NavBar,需要它
<div class="navbar">
<a href="<?php echo base_url('Userpanel/index');?>">PROFIILI</a>
<a href="<?php echo base_url('Userpanel/accounting');?>">LASKUTUS</a>
<a href="<?php echo base_url('Userpanel/commissions');?>">TOIMEKSIANNOT</a>
<a href="<?php echo base_url('Userpanel/logout');?>">KIRJAUDU ULOS</a>
</div>
然而,由于某种原因,我不断收到db_error和file_error未定义的错误。在寻找这个来源时,我开始使用断点变量来查看问题所在,并在“Navigointi Alku”断点处停止。然而,页面上的其他所有内容都可以正确呈现。似乎在某一点之后,$ data变量根本不再更新。页面上的其他所有内容都会正确呈现,但是在加载导航栏后,断点变量似乎停止更新,尽管该函数的执行持续到足以获得错误页面。
任何可能导致这种情况的想法?程序中的其他任何地方这些系统都可以正常工作,但是当上传图像时,它会带来麻烦。
尚未完成路由。我正在使用CodeIgniter 3。
答案 0 :(得分:0)
某些时间上传错误由于小事而发生 像file_size文件类型尝试此代码:
switch ($_FILES['file1']['error'])
{
case UPLOAD_ERR_OK:
echo "File uploaded succesfuly";
break;
case UPLOAD_ERR_INI_SIZE:
echo "Uploaded File is too big";
break;
case UPLOAD_ERR_PARTIAL :
echo "File is not completely uploaded";
break;
case UPLOAD_ERR_NO_FILE :
echo "No File was Selected";
break;