Musa Muaz
Musa Muaz

Reputation: 714

ZipArchive error : Showing the same result on the both conditions

I just want to test that weather the file is opening through the ZipArchive class.I am using the following code .but in both cases result comes : failed!

My First codes :

<?php

        $zip = new ZipArchive;

        if($zip->open("file.zip") === TRUE){
            echo "success";
        }else{
            echo "faailed!";
        }

    ?>

AND second codes :

<?php

        $zip = new ZipArchive;

        if($zip->open("file.zip") === FALSE){
            echo "success";
        }else{
            echo "faailed!";
        }

    ?>

But both condition it comes : faailed! . I am getting really fade up with this.My Php version is above 5.2.x (5.5.x)

Upvotes: 0

Views: 37

Answers (1)

mishu
mishu

Reputation: 5397

In the second case it's normal because, as you can see on the manual page here, the method doesn't return FALSE, it will give you an error code. Also that's how you can find your issue. You can store the return value in a variable and test it against the ones that can be returned (you can see them in that manual page).

So it would be something like:

$ret = $zip->open("file.zip");
switch ($ret) {
 case ZipArchive::ER_NOZIP:
 echo 'Not a zip archive';
 break;
 //and so on for all of them
}

Upvotes: 1

Related Questions