Welcome Guest, Not a member yet? Register   Sign In
upload not working for me
#1

[eluser]cotsweb[/eluser]
I am attempting to use CI's upload library for the first time and have run into trouble. I suspect I am doing something obvious and stupid but I just can't see it.

I attempt to upload an image called "facebook_picture.jpg" from my PC to the "/images/people/" directory with the new name "mark.jpg". I get a good response from upload->data() but no actual action and the data() fields contain only what I entered as configuration variables.

This is the code I am executing
Code:
function update_photo($id)
    {
        /*
         * Upload a new photo for the person, overwrite the existing one
         */
        log_message('debug', 'In update_photo');
        log_message('debug', 'uploading: ' . $_FILES['image_url']['name']);
        //
        $config['upload_path'] = '/images/people/';
        $config['file_name'] = 'mark.jpg';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';                // Allow any size host max is 64MB
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        $config['overwrite'] = true;

        $this->load->library('upload', $config);

        if ($this->upload->data('image_url')) {
            log_message('debug', 'Upload succeeded : ' . implode(',',$this->upload->data()));
        }
        else {
            log_message('debug', 'Upload failed ' . implode(',',$this->upload->display_errors()));
        }
    }

And this is what appears on the CI log;
Code:
DEBUG - 2012-10-31 17:13:31 --> In update_photo
DEBUG - 2012-10-31 17:13:31 --> uploading: facebook_picture.jpg
DEBUG - 2012-10-31 17:13:31 --> Upload Class Initialized
DEBUG - 2012-10-31 17:13:31 --> Upload succeeded : mark.jpg,,/images/people/,/images/people/mark.jpg,mark.jpg,,,,,,,,,
DEBUG - 2012-10-31 17:13:31 --> Final output sent to browser
DEBUG - 2012-10-31 17:13:31 --> Total execution time: 0.1897

And this is the code from the view;
Code:
<div id="picture">
        <p>Upload a new picture</p>
        &lt;?php echo secure_form_open_multipart("people/update_photo/$id");?&gt;
        <p>
            <label for="image_url">Photograph:</label>
            &lt;?php echo form_upload($image_url);?&gt;

        </p>

        <p>
            &lt;?php
            echo form_submit('submit', 'Upload');          
            ?&gt;
        </p>

        &lt;?php echo form_close();?&gt;

    </div>
Can anybody see my obvious error? Or am I completely misunderstanding how the upload library works (I did run through the tutorial and that worked fine for me).
#2

[eluser]cotsweb[/eluser]
Stupid error of course.

I had got confused by the example (which includes a function called do_upload()) and hadn't actually invoked do_upload. The working version is;

Code:
function update_photo($id)
    {
        /*
         * Upload a new photo for the person, overwrite the existing one
         */
        log_message('debug', 'In update_photo');
        log_message('debug', 'uploading: ' . $_FILES['image_url']['name']);
        //
        $config['upload_path'] = './images/people/';
        $config['file_name'] = 'mark.jpg';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';                // Allow any size host max is 64MB
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        $config['overwrite'] = true;

        $this->load->library('upload', $config);

        if ($this->upload->do_upload('image_url')) {
            log_message('debug', 'Upload succeeded : ' . implode(',',$this->upload->data()));
        }
        else {
            log_message('debug', 'Upload failed ' . implode(',',$this->upload->display_errors()));
        }
    }




Theme © iAndrew 2016 - Forum software by © MyBB