PHP allowed zip mimetypes

I know (from the answer to this question: .rar, .zip files MIME Type ) that most people check zip files in PHP as application/zipor application/octet-stream, but I have a few questions about this:

  • Is it safe to just check application/octet-stream(given that it application/octet-streamcan be used to describe many other types of files than just zip!). I know that I can check the file in other ways, but I thought that I should try to save everything as simple as possible.
  • I tried to check as many different actual types of zip codes as possible; but there are some that give unexpected results. I found 1 for which the type is mime application/x-external-editor, but PHP has problems with it (although the only error I get is Warning: ZipArchive::close() [ziparchive.close]: Invalid or unitialized Zip object) is this documented anywhere? Is there a list of actual x-mimetypes that PHP can handle?

Edit

In response to the following questions:

  • I am checking the mime type with $_FILES['fileatt']['type'], but using mime_content_type()gives the same result. Various zip files look like one of the following: 'application/zip', 'application/x-compressed', 'application/x-zip-compressed', 'application/x-compressed', 'multipart/x-zip'. I did not understand why I received an error message when the mime type was detected as application/x-external-editor.
  • zip, zip . .

, : , PHP application/x-external-editor:

if($zip->open($_FILES[fileatt]['tmp_name'])===TRUE)
{
    echo "success";
} else {
    echo "error";
} 

"",

$res = $zip->open($_FILES[fileatt]['tmp_name']);
if($res)
{
    echo "success";
} else {
    echo "error";
} 

""; , ==, ===, ?

:

$res = $zip->open($_FILES[fileatt]['tmp_name']);
if($res===TRUE)
{
    echo "success";
} else {
    echo $res;
} 

prints 19 - (http://uk3.php.net/manual/en/ziparchive.open.php) ?!

+3
1

mime, . exe mime text/plain, .

zip (0x04034b50), , 4 zip. . PKZIP Appnote.

zip, zip, , zip .

- :

$zip = zip_open('/path/to/file.zip');
if (is_int($zip)) {
    echo "Error $zip encountered reading the file, is it a valid zip?";
} else {
    echo "Thanks for uploading a valid zip file!";
}

zip_open , , , , .

: :

application/octet-stream: , , . , , 8- , . application/zip - mime, , . , , application/zip, $_FILES['fileatt']['type'], .

AFIK, mime_content_type() mime mime.types PHP. - .zip exe, application/zip. , .

Zip::open() TRUE, , . , == , true ==, TRUE. Zip::open, $res === true, . .

Bottom Line: , , mime, open. true, , ( , , , - zip ).

, .

+2

All Articles