Welcome Guest, Not a member yet? Register   Sign In
Form validation with Upload validation
#1

[eluser]_TTT_[/eluser]
I have a form and required fields. And also I have photo upload field its not required, but user must knows if they try to upload big photo or wrong file type.

I wrote:

Code:
if(($this->validation->run() == FALSE) OR ($this->upload->do_upload() == FALSE))
{
...Show validataion and Photo upload errors...
}

its work but if upload field is empty it is error:You did not select a file to upload.
because error "You did not select a file to upload." also return FALSE.

how to solve this problem ?
#2

[eluser]_TTT_[/eluser]
tried to eliminate this particular error.

just for test:

Code:
if($this->upload->display_errors() !== 'You did not select a file to upload.')
       echo $this->upload->display_errors();

and why i see: You did not select a file to upload. ? О_о
#3

[eluser]_TTT_[/eluser]
also I tried this:

Code:
if(($this->validation->run() == FALSE) OR (($this->upload->display_errors() !== 'You did not select a file to upload.') AND ($this->upload->do_upload() == FALSE)))
{

}

also dont work.
#4

[eluser]danmontgomery[/eluser]
Code:
if(!empty($_FILES)) {
    // a file was uploaded
}
#5

[eluser]_TTT_[/eluser]
if(!empty($_FILES)) {
$this->upload->do_upload();
$upload = TRUE;
} else {
$upload = FALSE;
}


if(($this->validation->run() == FALSE) or ($upload == true)) {
....
}

dosnt work, I have error: You did not select a file to upload.
I can not send the form data until the error appears
#6

[eluser]_TTT_[/eluser]
I think i found it:

Code:
if(!empty($_FILES['userfile']['name']))
{
...
}

but now I have some truble with: Cannot modify header information - headers already sent by
I will try to solve this problem
#7

[eluser]_TTT_[/eluser]
nope Sad
This dont work correct

Code:
if(!empty($_FILES['userfile']['name']))
{
  $upload = true;
  $this->upload->do_upload();
  $upload_error = $this->upload->display_errors());
} else {
  $upload = false; // if no files select its work.
}

if(($this->validation->run() == FALSE) or ($upload == true))
{

}

because if variable $upload will be always TRUE form wil never submit
if(($this->validation->run() == FALSE) or ($upload == true))
#8

[eluser]_TTT_[/eluser]
oh shi.... its works, I found it Smile

Code:
if(!empty($_FILES['userfile']['name']))
{
   $upload = true;
   if($this->upload->do_upload())
   {
      $upload = false;
   } else {
      $upload_error = $this->upload->display_errors();
   }
} else {
   $upload = false;
}




Theme © iAndrew 2016 - Forum software by © MyBB