0

im trying to check if the last 3 letter of a string are pdf but it doesnt work this is my code so far hope someone can help

$CV = $_POST["CV"];
$lengthCV =strlen($CV);

if(strpos("$CV","pdf",substr('$CV',$lengthCV - 3)) !== false){ 
    echo "your file is a pdf";
}
else{
    echo "you didnt upload a pdf file";
    die();  
}
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

Use This Code; Working Perfectly:

                $CV = trim($_POST["CV"]);    
                $FnameArr = explode('.',$CV);
                $ext = end($FnameArr);
                if(strtolower($ext)!='pdf'){
                    // YOUR CODE GOES HERE.
                }
                else{
                    echo "you didnt upload a pdf file";
                    die();  
                }