3

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.

4 Answers 4

1

add form tag in your html

<form enctype="multipart/form-data" name="" action=""></form>
Sign up to request clarification or add additional context in comments.

2 Comments

He has the form tag, it's form_open_multipart?
@BeatAlex, yes but it is not constructive
1

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);
        }
    } 

Comments

0

Your code seems good no error. Try below code to check if image upload or not may be it is path issue ? copy below code and put above

"$this->load->view('gallery');" 

this in your up function of controller.

if (! $this->upload->do_upload())
{
  $error = array('error' = $this->upload->display_errors());

 // uploading failed. $error will holds the errors.
}
else
{
  $data = array('upload_data' => $this->upload->data());

 // uploading successfull, now do your further actions
}

Comments

0

The problem was that the folder in which the image was to be uploaded had no permission to write, so I made that folder writable, and it works fine now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.