Welcome Guest, Not a member yet? Register   Sign In
Getting File Name after Upload for Database Storage
#1

[eluser]Gwarrior[/eluser]
As the title suggests, I am trying to create a script (for my backend CMS) that will 1) Upload a file and 2) Pull out the File Name so I can store it in the database, in order to retrieve it at a later time.

For some reason it just isn't working.

Here's the excerpt from my controller:
Code:
function work() {
        // set upload params
        $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);
        
        // check to see if user is logged in
        if ($this->session->userdata('logged_in') == TRUE) {
            $data['logged_in'] = $this->session->userdata('logged_in');
            $data['jobs'] = $this->db->query('SELECT * FROM jobs');
            if (isset($_POST['submitted'])) {
                // upload logo file then pull the filename out for db upload
                $holder_1 = $this->input->post('logo');
                $this->upload->do_upload($holder_1);
                $ul_data_1 = $this->upload->data();
                $qdata['logo'] = $ul_data_1['file_name'];
                
                // upload navimg file then pull the filename out for db upload
                $holder_2 = $this->input->post('navimage');
                $this->upload->do_upload($holder_2);
                $ul_data_2 = $this->upload->data();
                $qdata['navimg'] = $ul_data_2['file_name'];    
                
                // upload the rest
                $qdata['site'] = $this->input->post('sitename');
                $qdata['link'] = $this->input->post('link');
                $qdata['text'] = $this->input->post('text');
                $qdata['programs'] = serialize($this->input->post('programs'));
                // freeze out while testing - $qdata['images'] = serialize($this->input->post('images'));        
                $this->db->insert('jobs', $qdata);
                }
            $this->load->view('jobs', $data);
        } else {
            // if not logged in, redirect
            redirect('login', 'refresh');
        }
    }

And here is my view:
Code:
<h2>New Completed Job</h2>
&lt;form action="" enctype="multipart/form-data" method="post"&gt;
<h3>Site Name:</h3>
&lt;input type="text" name="sitename" value="" /&gt;
<h3>Logo:</h3>
&lt;input type="file" name="logo" value="" /&gt;
<h3>Link:</h3>
&lt;input type="text" name="link" value="" /&gt;
<h3>Programs:</h3>
&lt;input type="checkbox" name="programs[]" value="(X)HTML" /&gt;(X)HTML<br />
&lt;input type="checkbox" name="programs[]" value="PHP" /&gt;PHP<br />
&lt;input type="checkbox" name="programs[]" value="JavaScript" /&gt;JavaScript<br />
&lt;input type="checkbox" name="programs[]" value="JQuery" /&gt;JQuery<br />
&lt;input type="checkbox" name="programs[]" value="Photoshop" /&gt;Photoshop<br />
&lt;input type="checkbox" name="programs[]" value="Illustrator" /&gt;Illustrator<br />
&lt;input type="checkbox" name="programs[]" value="Dreamweaver" /&gt;Dreamweaver<br />
&lt;input type="checkbox" name="programs[]" value="MySQL" /&gt;MySQL
<h3>Images:</h3>
&lt;input type="file" name="images[]" value="" /&gt;
<h3>Nav Image:</h3>
&lt;input type="file" name="navimage" value="" /&gt;
<h3>Text:</h3>
&lt;textarea name="text" style="width: 400px; height: 200px; overflow: scroll;"&gt;&lt;/textarea>
<br />
&lt;input type="submit" name="submitted" /&gt;
&lt;/form&gt;

See anything I should change around to make this work (and yes, I know I should use a model for my DB functions)? Any help would be greatly appreciated!
#2

[eluser]gtech[/eluser]
I can't see anything obvious.. but it is late.... anyway... the form action is blank.. are you intending to post to the same controller function?

do you know where the code is failing, do you see any error messages?

Put some echos or print_r's in your controller function code just to ensure the variables are set to what you think they are and also to see if the if statements are being passed

are your file uploads working?

I would put some checks in to ensure they are working e.g.:

Code:
...
     if ( ! $this->upload->do_upload($holder_1))
     {
         echo($this->upload->display_errors());
     } else {
         $ul_data_1 = $this->upload->data();
...


If you are seeing no error messages, debugs your friend, just remember to take the echos and print_rs out when finished.
#3

[eluser]Gwarrior[/eluser]
Still not working. I've been debugging like crazy.

Appreciate the response, but anyone else have any ideas?
#4

[eluser]slowgary[/eluser]
You ever get this sorted out? I see you're passing the contents of your form inputs instead of the name. So you have:
Code:
$holder_1 = $this->input->post('logo');
$this->upload->do_upload($holder_1);
which would pass the contents of your 'logo' input, but the do_upload method expects the NAME of the input...
Code:
$this->upload->do_upload('logo');




Theme © iAndrew 2016 - Forum software by © MyBB