Welcome Guest, Not a member yet? Register   Sign In
help with file upload
#1

[eluser]dadamssg[/eluser]
I did have an event submission form with no file upload but now i want to have the option to upload a picture. Couple questions about this.

What is the "field name"?

How do i make the upload validation NOT run if they have chosen not to upload anything?

The user guide uses an example with only uploading a file and using the do_upload function. I'm not seeing how i call that function if something was chosen to be uploaded.
#2

[eluser]Colin Williams[/eluser]
The name attribute of the input tag

Code:
<input type="file" name="userfile" />

Check files array

Code:
if (isset($_FILES) and count($_FILES))
{
  // Config, etc
  $this->upload->do_upload();
}
#3

[eluser]dadamssg[/eluser]
thanks, is there a way to check to see if the upload is valid without actually uploading it?
#4

[eluser]Colin Williams[/eluser]
PHP.net has all this covered, if you're at all interested http://us2.php.net/manual/en/features.fi...method.php
#5

[eluser]dadamssg[/eluser]
well yeah i know how to do it without codeigniters file upload class...was wondering if you could do it WITH the help of CI.
#6

[eluser]Colin Williams[/eluser]
That page shows a way to validate a file upload, functionality that doesn't exist in CI.
#7

[eluser]flaky[/eluser]
Here in the userguide you have the File Upload Class
read it
http://ellislab.com/codeigniter/user-gui...ading.html
#8

[eluser]dadamssg[/eluser]
is there a way to use set_value for a file upload?
#9

[eluser]Colin Williams[/eluser]
You clearly have little understanding of how file uploading works on the web. What good would set_value do you with a file input?
#10

[eluser]maria clara[/eluser]
hi,

i have here my file upload script for image. you can edit it for helpful tips in your CI.

CONTROLLER:
Code:
function index()
    {    
        $config['upload_path'] = './reports/module/';
        $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());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
                $file_data = $this->upload->data();
                $file_name = $file_data['file_name'];
                    $form_data = array(
                               'file_name' => $file_name
                        );
                          
            
            if ($this->At_reportmodel->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
            {
                redirect('at_reports/success');   // or whatever logic needs to occur
                
            }
            else
            {
            echo 'An error occurred saving your information. Please try again later';
            // Or whatever error handling is necessary
            }
        }
    }
    function success()
    {
            echo 'this form has been successfully submitted with all validation being passed.
            
    }
    

}

MODEL:
Code:
function SaveForm($file_name)
    {
        $this->db->insert('reports', $file_name);
        
        if ($this->db->affected_rows() == '1')
        {
            return TRUE;
        }
        
        return FALSE;
    }

VIEW:
Code:
<?php echo $error;?>

<?php echo form_open_multipart('at_reports');?>
        <label for="userfile">Link</label>
&lt;input type="file" name="userfile" size="20" /&gt;


&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;




Theme © iAndrew 2016 - Forum software by © MyBB