If (!$typeOK) {do this;} Is it ok to use ! here?

It kept giving me a type OK error until I changed it at the bottom from:
Thanks.


if (!$typeOK) {
  $result[] = "$file type not OK";
}

To:

if ($typeOK = false) {
  $result[] = "$file type not OK";
			}



$typeok = true;       
          switch ($_FILES['image']['type'][$number])
          {
              case "image/gif":
                  $src = imagecreatefromgif($udfile);
                  break;                  
              case "image/jpeg":
                  // Both regular and progressive jpegs 
              case "image/pjpeg":
                  $src = imagecreatefromjpeg($udfile);
                  break;                  
              case "image/png":
                  $src = imagecreatefrompng($udfile);
                  break;                  
              default:
                  $typeok = false;
                  break;
          }

		  if ($typeOK = false) {
		    $result[] = "$file type not OK";
			}


I see how that makes more sense. Thanks.

The other thing I would recommend is always default to the worst case scenario:



// The type is not ok until it has been proved ok
$typeok = false;       

          switch ($_FILES['image']['type'][$number])

          {

              case "image/gif":

                  $src = imagecreatefromgif($udfile);
                 $typeok = true;

                  break;                  

              case "image/jpeg":

                  // Both regular and progressive jpegs 

              case "image/pjpeg":

                  $src = imagecreatefromjpeg($udfile);
                  $typeok = true;

                  break;                  

              case "image/png":

                  $src = imagecreatefrompng($udfile);
                  $typeok = true

                  break;                  

              default:

          }

That would be assignment which would return the value and the value will always be false.

So $typeOK = false is not OK because it only uses one = sign.

Thanks.

$typeOK == false

||

!$typeOK

||

$typeOK === false

This


if ($typeOK = false) {

will always evaluate to TRUE, because the assignment of the value false to the variable will always succede.

Edit: the OP’s problem is that $typeok is not equal to $typeOK