简体   繁体   中英

Not recognizing the variable neither the else statement

If is working only if the statement is false. when it's right it doesnt do anything.

I first tried with if - else , but my code was never entering the else statement. Then , as you can see i tried with a flag but the same thing is happening.

if (isset($_POST['upload'])){

       $filename = $_FILES['file']['name'];
       $allowed = array ('kml','xml');
       $ext = pathinfo($filename ,PATHINFO_EXTENSION);
       if(!(in_array($ext,$allowed))){
           echo '<script type="text/javascript">alert("Error, Not a kml File");</script>';
       }
        else {

           echo '<script type="text/javascript">alert("This,is a kml file");</script>';
       }
}

I expect that if i upload the right kml file , i want to echo that is right.

Else statement is missing in your condition, Please do this way -

if (isset($_POST['upload'])){
       //$filename = $_FILES['file']['name'];
       $fileMimeType = $_FILES['file']['type'];
       // Check the mime type of your xml & kml file 
       $allowed = array ('text/xml','application/xml'); 
       //$ext = pathinfo($filename ,PATHINFO_EXTENSION);
       if(!(in_array($fileMimeType ,$allowed))){
           echo '<script type="text/javascript">alert("Error, Not a kml File");</script>';
       }
       else {
           echo '<script type="text/javascript">alert("This,is a kml file");</script>';
       }
}
if (isset($_POST['upload'])){
       $filename = $_FILES['file']['name'];
       $allowed = array ('kml','xml');
       $ext = pathinfo($filename ,PATHINFO_EXTENSION);
       if(in_array($ext,$allowed)){
           echo '<script type="text/javascript">alert("This,is a kml file");</script>';
       }
       else {
           echo '<script type="text/javascript">alert("Error, Not a kml File");</script>';
       }
}

Try this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM