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

[eluser]codeign00b[/eluser]
Hi codeignitr experts.

I need help with uploading files with codeigniter. My problem is that I can't upload anything, everytime I get You did not select a file to upload.

Here is the function in my controller:

Code:
function upload()
    {
        //loading libraries
        $data['message'] = '';
        $this->load->library( array('form_validation', 'email') );
        $this->load->helper( array('string', 'array', 'date') );
        $this->load->helper('form');
        $config['upload_path'] = './files/';
        $config['allowed_types'] = 'jpg';
        $config['max_size'] = '5000';
        $this->load->library('upload', $config);
      
        //form validation
        $this->form_validation->set_rules('userfullname', 'User Full Name', 'matches[userfullname]|xss_clean');
        $this->form_validation->set_rules('filename', 'File', 'trim');
        if ($this->form_validation->run() == FALSE)
        {
            //page has not run or validation error
            $data['main_content'] = 'view_files_upload';
            $this->load->view('view_main', $data);
        }
        else
        {      
            //get userid
            $this->load->model('Model_files');
            $userfullname = $this->input->post('userfullname');
            $userid = $this->Model_files->get_userid($userfullname);

            //get file date by Y-M-D for filtering
            $reportyear = date("Y");
            $reportmonth = date("n");
            $reportday = date("d");

            if (!$this->upload->do_upload())
            {
              $error = array('error' => $this->upload->display_errors());
                print_r($error);
            }


            else
            {

        $this->upload->do_upload();
                $data = array('upload_data' => $this->upload->data());

                $filename = $data['file_name'];
                
                $filestable= array(
                           'userid'=> $userid['userid'],
               'filename'=>$filename,
                           'fileowner'=>$userfullname,
                 'fileyear'=>$fileyear,
                           'filemonth'=>$filemonth,
                           'fileday'=>$fileday
                             );
                $this->Model_files->upload_files($filestable);
                redirect('files/upload');
            }
        }        
    }

I have note that I have server settings like this:

/home
|
+ app
|
+ application
|
+ system
|
+ files
|
+ scripts
|
+ index.php

index.php is symlinked to www folder

View file (form):

<?php
Code:
...
$submit = 'class="submit"';
$file = array(
              'name'        => 'filename',
              'id'          => 'filename',
              'value'       => (set_value('filename')),
              'type'       => 'file',

            );
echo '<div id="form-container">';
echo form_open_multipart('files/upload');
echo '<label for="userfullname" id="labeluserfullname">User Full Name</label>';
echo form_input('userfullname', set_value('userfullname'));
echo '<br></br>';
echo '<label for="filename" id="labelfile">Select File</label>';
echo form_input($file);
echo '<br></br>';
echo form_submit('submit', 'Upload', $submit);  
echo form_close();
echo '</div>';
?&gt;
...

Please help me with.

Than you all!

p.s. ignore error pages, they are set to view the errors when developing.


Messages In This Thread
Upload File Problem - by El Forum - 04-15-2011, 09:58 AM
Upload File Problem - by El Forum - 04-15-2011, 11:15 AM
Upload File Problem - by El Forum - 04-15-2011, 11:25 AM
Upload File Problem - by El Forum - 04-15-2011, 11:50 AM
Upload File Problem - by El Forum - 04-15-2011, 11:58 AM
Upload File Problem - by El Forum - 04-15-2011, 12:07 PM
Upload File Problem - by El Forum - 04-15-2011, 04:32 PM
Upload File Problem - by El Forum - 04-16-2011, 12:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB