Welcome Guest, Not a member yet? Register   Sign In
Upload Error
#1

[eluser]E303[/eluser]
I have been trying to work this out for some time. When I go to upload a file I get this error:

A PHP Error was encountered

Severity: Warning

Message: Illegal offset type in isset or empty

Filename: libraries/Upload.php

Line Number: 138

The Controller:

Code:
function For_Sale_add()
    {
        $this->load->model('admin/Admin_Model');
        $this->load->model('Admin_Model');
        
        // File Upload
        $config['upload_path']        = './images/forsale/';
        $config['allowed_types']    = 'gif|jpg|png';
        $config['max_size']            = '2000';
        $config['max_width']        = '300';
        $config['max-height']        = '300';
        
        $this->load->library('upload');
        $this->upload->initialize($config);
        
        $forsaleimage = $this->upload->data();
        
        $this->upload->do_upload($forsaleimage);
        $this->Admin_Model->ForSale_add();

        $data['query'] = $this->Admin_Model->Flakes_navigation();

        $this->load->view('admin/main_admin_view', $data);

        

    }

The Model:

Code:
function ForSale_add()
    {
        $file = $this->upload->data();
        $data = array(
                        'title'        => $_POST['title'],
                        'body'        => $_POST['body'],
                        'image'        => $file['file_name']
                    );
        $this->db->insert('for_sale', $data);            
        
    }

The Form
Code:
<?=form_open_multipart('main_admin/For_Sale_add');?>
            
            <br />
            <fieldset>
            <label>Item Title:</label>
            &lt;input type="text" name="title" /&gt;
            <p>
            <label>Description:</label><br />
            &lt;textarea name="body" id="ajaxfilemanager" cols="70" rows="20"&gt;&lt;/textarea&gt;
            </p>
            <label>Image:</label>
            &lt;input type="file" name="userfile" /&gt;<br />
            <em>Max size: 300 x 300. Max file size: 2000kb</em>
            </fieldset>
            
            <br />
                &lt;input type="submit" value="Save" class="flake_submit"/&gt;

            &lt;?=form_close();?&gt;

Any ideas why?
#2

[eluser]Michael Wales[/eluser]
The reason is because you are passing an array to the do_upload() method of the Upload class.

Code:
$forsaleimage = $this->upload->data();
This line populates an array with information about the file you just uploaded.

Code:
$this->upload->do_upload($forsaleimage);
This line attempts to upload a file, the parameter should be the field name from the form.

Since you are using the default field-name, of 'userfile', you don't need to pass anything to do_upload(). Change it to this and you should be fine:
Code:
$this->upload->do_upload();
#3

[eluser]ELRafael[/eluser]
Code:
$data = array(
    'title'        => $_POST['title'],
    'body'        => $_POST['body'],
    'image'        => $file['file_name']
    );

And what is $file['file_name']. Use the $_FILES....
#4

[eluser]Michael Wales[/eluser]
No, he's right. Look one line up:

Code:
$file = $this->upload->data();
        $data = array(
                        'title'        => $_POST['title'],
                        'body'        => $_POST['body'],
                        'image'        => $file['file_name']
                    );

He's getting the metadata of the file, assigning it to an array called $file, and then using that to populate his database. Everything's good there.

Of course, this makes me question why he's getting the data of the file in the Controller:
Code:
$forsaleimage = $this->upload->data();
You're not doing anything with it?
#5

[eluser]E303[/eluser]
thanks for that. I have stopped that error now.. However everything seems to run through without a problem yet the file doesn't get uploaded.

The directory is set to 777:
Code:
$config['upload_path']        = '/public_html/images/forsale/';

i have even tried
Code:
$config['upload_path']        = './images/forsale/';
and
Code:
$config['upload_path']        = './uploads';

nothing works.

anyideas?
#6

[eluser]Jamongkad[/eluser]
Did you try checking your htaccess file? I had that problem once even with the directory set to 777. I was wondering what the hell was happening. I checked my .htaccess file and saw that the target directory I was uploading files to wasn't listed.
#7

[eluser]E303[/eluser]
I have had a look at my .htaccess file. The only code in there is to remove the index.php from the URI..

I was able to upload the files using standard PHP uploading I just can't get it to work through CI




Theme © iAndrew 2016 - Forum software by © MyBB