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

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

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


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

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

if ($this->form_validation->run() == FALSE)
  // do something

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:
if ( $_FILE['yourfile']['size'] > 0 )
    //the user has selected a file

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

i get the following error
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _FILE

Filename: controllers/banner.php

Line Number: 127

Any other suggestions would be great.

Arrghh .. that's what i get for quick posting... I should have seen this before.

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

All is working now.


Theme © iAndrew 2016 - Forum software by © MyBB