jeudi 6 février 2020

If condition in checking file exist PHP

I have this php code :

$controlNum = '0111111';
$path = 'http://00.000.00:0000/Files/';

$version1 = '201909R14';
$version2 = '201909R16';

$path1 = $path.'/'.$controlNum.'/FIRST/MY%20DATA/'.$controlNum.'-FOR%20RECEIPT%20(with%20copy)%20FINAL%20DATA/'.$controlNum.'-'.$version1.'.txt' ; // declare exact path of the data
$path2 = $path.'/'.$controlNum.'/FIRST/MY%20DATA/'.$controlNum.'-FOR%20RECEIPT%20(with%20copy)%20FINAL%20DATA/'.$controlNum.'-'.$version2.'.txt' ; // declare exact path of the data    

if (fopen($path1, "r")) {
    echo 'FILE FOUND ';
}
    if(fopen($path2, "r")){
        echo 'FILE FOUND ';
    }else{
        echo 'FILE NOT FOUND ';
}

It gives an OUTPUT like this :

FILE FOUND FILE NOT FOUND

But what I want is to only output either FILE FOUND and FILE NOT FOUND only.

If first condition is false it must not echo, it must go for the second if condition.

How can I achieve that? sorry for this question, but i'm still learning..

Aucun commentaire:

Enregistrer un commentaire