I'm trying to add a file upload function in my website using codeigniter's upload library.
here's my view file (display.php):
<html>
<body>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="submit" name="submit" id="submit" value="submit"/>
</form>
</body>
</html>
and here's the controller:
public function testupload()
{
if ( ! empty($_FILES))
{
echo 'start upload';
$config['upload_path'] = './assets/img/tempfile/';
$this->load->library('upload');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('filename'))
{
echo 'error!';
}
else
{
echo 'success!';
}
echo 'end upload';
}
$this->load->view('display', $this->data);
}
but the code seems to stop after $this->upload->initialize($config);
the file was not uploaded, and there was no message at all. only the 'start upload'
message appeared; the echo 'success'
, echo 'error'
, and echo 'end upload'
do not appear.
why is that? can anyone help me??
$this->upload->display_errors()
to debug the errorsini_set('display_errors', '1'); error_reporting(E_ALL);
and print this one as well$this->upload->display_errors()
;echo 'blabla';
worked if put after$this->upload->do_upload('filename');
I tried @Naga 's advice but still nothing.action="<?php echo base_url('controller/function');?>"
don't for get to autoload url helperstart upload
message appeared, but nothing after that.