Jump to content


Photo

if ($_FILES['creature_image[error]']=0)//proper file uploaded checker


  • Please log in to reply
4 replies to this topic

#1 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 02 May 2013 - 05:16 PM

How would I write the following if statement properly to make sure there aren't any errors with the file?


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,130 posts
  • LocationWA

Posted 02 May 2013 - 05:46 PM

if ($_FILES['creature_image']['error'] == 0) {


#3 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 03 May 2013 - 12:28 AM

Why was it the double equals that time, but the previous time it was the single equals?


Edited by Q695, 03 May 2013 - 12:29 AM.

if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#4 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,130 posts
  • LocationWA

Posted 03 May 2013 - 02:45 AM

When?

#5 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,540 posts

Posted 03 May 2013 - 02:51 AM

i'm not sure what previous time you are referring to, but for the line of code in this thread, DavidAM told you in your previous thread that one equal sign means that you are making an ASSIGNMENT, not a comparison -
 
 
 

1) A single equals-sign is ASSIGNMENT, it takes two to COMPARE:

 
an argument can be made that you need === (three equal signs, a value and type match) for this line of code, since your image uploader script isn't testing if the $_FILES array is even set/not-empty. when $_FILES is empty due to an error or an upload form has not been submitted (your code isn't testing if any form was submitted), an empty $_FILES array will match a zero using two == signs. using three === (a value and type check), will only be successful if the $_FILES array is not empty and the ['error'] is a zero value.

 
FYI, why you need to learn the meaning of the code -

one = sign is an assignment operator i.e $var = some_value;. when used in a conditional test - if($var = some_value) ... while($var = some_value) the assignment is made and the value that was assigned is used in the conditional test.

two == signs is an equal value test (the types can be different i.e null/empty is == to a 0.)

three === signs is an exact value test (the value and types must be the same i.e. null/empty is not === 0.)

Edited by mac_gyver, 03 May 2013 - 03:01 AM.

multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com