CodeIgniter Forums
file uploaded check - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: file uploaded check (/thread-29630.html)



file uploaded check - El Forum - 04-15-2010

[eluser]pendalpusher[/eluser]
I am trying to put a file input on a field, that the user can use to upload a new replacement image if they want.

How do i access the field to see if it is empty or full before trying to upload the file?

i am using
Code:
<?=form_upload('userfile');?>

i just want to see if the field is empty when it is posted.

Thanks,
P


file uploaded check - El Forum - 04-15-2010

[eluser]Bart v B[/eluser]
Then you need to setup some validation rules Wink
Take a look in the userguide: Form validation class

in youre controller:
Code:
<?php

$this->form_validation->set_rules('userfile', 'userfile', 'required');

if ($this->form_validation->run() == FALSE)
{
  $this->load->view('myform');
}
else
{
  // do something
}



file uploaded check - El Forum - 04-16-2010

[eluser]alphane[/eluser]
Setting it as a required field using form_validation will mean the user has to replace an image every single time.

You can determine whether a file has been uploaded using either the file objects error code or file size as so:
Code:
if ( $_FILE['yourfile']['size'] > 0 )
{
    //the user has selected a file
}



file uploaded check - El Forum - 04-16-2010

[eluser]pendalpusher[/eluser]
when i use this code
Code:
if ( $_FILE['userfile']['size'] > 0 )
{
    //the user has selected a file
}

i get the following error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _FILE

Filename: controllers/banner.php

Line Number: 127

Any other suggestions would be great.
C


file uploaded check - El Forum - 04-16-2010

[eluser]pendalpusher[/eluser]
Arrghh .. that's what i get for quick posting... I should have seen this before.

$_FILES ... not .... $_FILE.

All is working now.

thanks,