Welcome Guest, Not a member yet? Register   Sign In
Uploading pictures
#1

[eluser]reyntjensw[/eluser]
So as you can see, I have an add_photo view with a simple form in it.
When I fill in all the info, everything except the picture is uploaded and added in my database.

This is strange because I don't get an error everything is added except the picture info.

This is the add_photo view
Code:
<?php
        echo form_open_multipart("photoalbum/do_upload");
        echo "<p>";
        echo form_label("Categorie");
        create_dropdown("photoalbum_category_id", $cat, "id","title_nl");
        echo "</p><p>";
        echo form_label("Afbeelding");
        echo form_upload('userfile');
        echo "</p><p>";
        echo form_label("Omschrijving");
        echo form_input("description");
        echo form_submit('upload', 'Upload');
        echo form_close();
    ?&gt;
This is my controller
Code:
function add_photo() {
        $dbArr['cat'] = $this->photoalbum_category_model->get_all();

        $this->template->write_view("content", "/photoalbum/new_image",$dbArr);
        $this->template->render();
    }
          function do_upload() {

        $config['upload_path'] = realpath(APPPATH . "../images/photoalbum/");
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '10000';
        $config['max_width']  = '10240';
        $config['max_height']  = '7680';

        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $file_data = $this->upload->data();
        $data = array(
                'photoalbum_category_id' => $this->input->post("photoalbum_category_id"),
                'description' => $this->input->post("description"),
                'file_name'      => $file_data['file_name']
        );
        $this->photoalbum_model->insert($data);
        redirect("/photoalbum/index");
    }

What am I doing wrong?
#2

[eluser]Buso[/eluser]
Don't you have to write this somewhere? $this->upload->do_upload()
#3

[eluser]reyntjensw[/eluser]
Hi Buso,

I have, if you count from the bottom up, it's on the 9th line.
#4

[eluser]Buso[/eluser]
Are you sure? Smile
#5

[eluser]reyntjensw[/eluser]
I did check it again and again and again and you are right.
I was missing this line.

I have one more question, I'd like to build a photoalbum, so it's possible that someone uploads a picture with the same name as an existing one.
So I'd like to create a folder when someone uploads a picture. (and put the new picture in the new folder)

I did try to work with the select_max function, to get the new ID the new picture would get. But that isn't so a good solution (I think). Is there a better solution?
#6

[eluser]Buso[/eluser]
I'm not sure if I understand what you need

For the image id's, just use auto_increment in that field

And for the filename, i think it's better to change it so there are no collisions.

Usually I use the image id for the filename, so they are unique. You can add something else

if you need them to be descriptive, like dog-running-845.jpg, where 845 is the image id.
#7

[eluser]reyntjensw[/eluser]
That's just what I wanted to know.
Thanks for your advise.




Theme © iAndrew 2016 - Forum software by © MyBB