Reputation: 714
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!
<?php
$zip = new ZipArchive;
if($zip->open("file.zip") === TRUE){
echo "success";
}else{
echo "faailed!";
}
?>
<?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
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