views:

71

answers:

1

I can't get my images to upload no matter what i do. Below is the code that is in my model:

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

        return $error;
    }   
    else
    {
        $data = array('upload_data' => $this->upload->data());

        return $data;
    }

Here is the code that is in my controller:

function do_upload()
{
    $this->Upload_model->do_upload();

}

And here is my form:

<html>
<head>
<title>Upload Form</title>
</head>
<body>



<?php echo form_open_multipart('upload/do_upload');?>
<?php if(isset($buttons)) : foreach($buttons as $row) : ?>
<h2><?php echo $row->name; ?></h2>
<input type="file" name="userfile" size="20" />
<input type="hidden" name="oldfile" value="<?php echo $row->image_url; ?>" />
<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<br /><br />
<label>Url: </label><input type="text" name="url" value="<?php echo $row->url; ?>" /><br /><br />
<input type="submit" value="submit" />

</form>

<?php endforeach; ?>
<?php endif; ?>

</body>
</html>

Can someone tell me what it is that i'm doing wrong? I'm a complete newbie to codeigniter and it is really leaving me at a dead end. As well as this I want to be able to write the path of the file to my database but i can't figure that out either so if someone has an answer or even point me in the right direction I would be extremely grateful. Thanks

EDIT -----------

The image i was uploading was too tall/wide. But if someone could point me in the direction of how to write the filepath to the database, that would be great!

+1  A: 

Did something similar with a project - basically you just need to turn the path into a string and write it to your db...

$fileup = $this->upload->data();
    $myfilepath = $fileup['file_name'];
    $databack = array(
        'your_field'=> 'http://www.yourserver.com/location/'.$myfilepath.'',
    ); 
    $DB->where('your_id_field', $id_value);
    $DB->update('your_table', $databack);  

The trickiest bit is just tying it to your database!

eddt