Welcome Guest, Not a member yet? Register   Sign In
file uploaded check
#1

[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
#2

[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
}
#3

[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
}
#4

[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
#5

[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,




Theme © iAndrew 2016 - Forum software by © MyBB