Mitul Dabhi
answered Nov 30 '-1 00:00
you can check file is valid zip or not by following code
$zipcontent=file_get_contents("test.zip");
if (strpos($zipcontent, "\x50\x4b\x03\x04") === false)
{
echo "it is not zip ";
}
so if in your code . you can put use like this
$uploads_dir=dirname(__FILE__).DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR;
$tmp_name = $_FILES["file"]["tmp_name"];
$name = basename($_FILES["file"]["name"]);
if(move_uploaded_file($tmp_name, "$uploads_dir/$name")){
//successfully uploaded
$filemetadata=pathinfo($name);
if($filemetadata['extension']=='zip') {
//extra checking for zip validation
$zipfilecontent=file_get_contents("$uploads_dir/$name");
if (strpos($zipfilecontent, "\x50\x4b\x03\x04") === false)
{
echo "I AM NOT ZIP";
}
else {
//extract it
}
}
}
hope it work