gallery.php - View
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>CI Gallery</title>
</head>
<body>
<div id="upload">
<?php
$this->load->helper("form");
echo form_open_multipart('gallery/up');
?>
<input type="file" name="file">
<?php
echo form_submit('upload','Upload');
echo form_close();
?>
</div>
</body>
</html>
gallery.php-controller
<?php
class Gallery extends CI_Controller {
function index()
{
$this->load->view('gallery');
}
function up()
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload',$config);
$this->upload->do_upload('file');
$this->load->view('gallery');
}
}
These are my coding files. Here the file is not being uploaded. Someone please help. I feel that the library upload fails to get loaded and hence it stop working. If that is the problem how to come over that.
add form tag in your html
<form enctype="multipart/form-data" name="" action=""></form>
you can write the uploading image server side code
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())
{
$error = array('error' => $this->upload->display_errors());
print_r($error); //debug it here
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With