I don't get it.... I'm trying to make an upload script. While it's working fine I was now trying to imply some error handling. But one thing is making me crazy. I just want to check, if a value is NOT in an array.
But I'm always getting a blank page. Since my English isn't the best, (and I hope I can explain my problem good enough), I will show a small part with the first if-statement:
session_start();
$errors = array();
$formData = $_POST;
function getFile( $filename , $formData ) {
$allowedExts = array("pdf");
$temp = explode(".", $_FILES["uploaded_file"]["name"]);
$extension = end($temp); // gives me "pdf"
$mimes = array('application/pdf');
if (!in_array($_FILES['uploaded_file']['type'],$mimes ) ||
!in_array($extension, $allowedExts, true))
{
$errors['fileformat'] = "Wrong file format!";
}
if(count($errors) === 0){
sendMailWithAttachment($_FILES["uploaded_file"]["tmp_name"],
$_FILES["uploaded_file"]["name"],
$formData); //this function is working...
}else{
$_SESSION['error'] = $errors;
header("Location: no_success.php");
exit();
}
}
$name_of_uploaded_file =basename($_FILES['uploaded_file']['name']);
getFile( $name_of_uploaded_file, $formData );
So this code (above) gives me a blank page. If I JUST change the "in_array"-line to:
if (in_array($_FILES['uploaded_file']['type'],$mimes ) ||
in_array($extension, $allowedExts))
{
So without the ! at the beginning. Everything is working (except from the fact, that I need the opposite result)
I also tried:
if ( in_array($_FILES['uploaded_file']['type'],$mimes) === false ||
in_array($extension, $allowedExts, true) === false){
I also tried:
if ( in_array($_FILES['uploaded_file']['type'],$mimes) == false ||
in_array($extension, $allowedExts, true) == false)
{
I also tried:
if (in_array($_FILES['uploaded_file']['type'],$mimes ) === 0 ||
in_array($extension, $allowedExts, true) === 0)
{
I also tried:
if (in_array($_FILES['uploaded_file']['type'],$mimes ) == 0||
in_array($extension, $allowedExts, true) == 0)
{
And all of this variants I also tried just with one if-statement, like:
if (in_array($extension, $allowedExts, true) === 0) {
All of them are making me getting a blank page. I don't understand this, because I just want to get the opposite function of "in_array" and the "in_array" itself just works fine.
Hope someone can help me. Thank you