$extension = "jpg"
if($extension != "jpg" || $extension != "gif" || $extension != "png") die("only jpg, gif, png acceptable");
it always seems to die().
$extension = "jpg"
if($extension != "jpg" || $extension != "gif" || $extension != "png") die("only jpg, gif, png acceptable");
it always seems to die().
You want && not ||.
Read it outloud as:
"If x doesn't equal Y OR x doesn't equal N".
Clearly, it doesn't matter what x equals, as long as Y and N aren't equal, the statement will always be true :)
Since $extension cannot be "jpg", "gif" and "png" at the same time, at least two of the sub-conditions are true.
And, since you're using or (||) instead of and (&&), any true sub-condition will render the entire condition true.
You want something like:
if (($extension != "jpg") && ($extension != "gif") && ($extension != "png")) {
die ("only jpg, gif, png acceptable");
}
$extension = "jpg"
if($extension != "jpg" && $extension != "gif" && $extension != "png") die("only jpg, gif, png acceptable");
This may work
You are using the NOT EQUAL TO operator with a bunch of ORs.
$extension = "jpg"
if ($extension != "jpg" ||
$extension != "gif" ||
$extension != "png")
die("only jpg, gif, png acceptable");
You could fix this one of two ways:
|| to &&$valid = array('jpg' => true, 'gif' => true, 'png' => true);
if (!isset($valid[$extension])) {
// not a valid extension
}
Reasons are already explained, moreover you can simply do this, with the result you expected:
$extension = "jpg";
if(!in_array($extension,array("jpg","gif","png"))){
die("only jpg, gif, png acceptable");
}