docx file mime wrong type back getMimeType - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: docx file mime wrong type back getMimeType (/showthread.php?tid=87205) Pages:
1
2
|
docx file mime wrong type back getMimeType - ijurisic - 03-24-2023 Hello, When I check mime type I got wrong type for docx. Code: PHP Code: $path='test.docx'; I got: application/octet-stream But if use file from bash: file -b --mime-type 'test1.docx' I got: application/vnd.openxmlformats-officedocument.wordprocessingml.document Any idea what is problem? RE: docx file mime wrong type back getMimeType - kenjis - 03-24-2023 I got: application/vnd.openxmlformats-officedocument.wordprocessingml.document Upgrade CI4 if you use older version. RE: docx file mime wrong type back getMimeType - ijurisic - 03-26-2023 I using CI 4.3.2. Tested on Debian 11 (php 7.4) and Debian 12 (php 8.2). Simple way for get error:
RE: docx file mime wrong type back getMimeType - kenjis - 03-27-2023 Yes, the file is "application/octet-stream". And the file command also returns it on my macOS. $ file -b --mime-type test1.docx application/octet-stream RE: docx file mime wrong type back getMimeType - JustJohnQ - 03-27-2023 It looks like LibreOffice changes the mime type. I tested using a native PHP function: PHP Code: $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type - all mimetype extension When I add an image to the doc in LibreOffice, the mime type changes to application/octet-stream. RE: docx file mime wrong type back getMimeType - ijurisic - 03-27-2023 (03-27-2023, 12:46 AM)kenjis Wrote: Yes, the file is "application/octet-stream". When I try got diferent result from file: file -b --mime-type test1.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document But from CI4 I got: application/octet-stream RE: docx file mime wrong type back getMimeType - kenjis - 03-27-2023 Anyway, it is an issue in finfo_file(), not in CI4. So we cannot fix it. Please send a bug report to the PHP Group. RE: docx file mime wrong type back getMimeType - ijurisic - 03-27-2023 (03-27-2023, 01:35 AM)kenjis Wrote: Anyway, it is an issue in finfo_file(), not in CI4. So we cannot fix it. Thanks, and sry for post on wrong place. RE: docx file mime wrong type back getMimeType - ijurisic - 03-27-2023 (03-27-2023, 12:46 AM)JustJohnQ Wrote: It looks like LibreOffice changes the mime type. If update this: PHP Code: $finfo = finfo_open(FILEINFO_MIME_TYPE) with: PHP Code: $finfo = finfo_open(FILEINFO_MIME_TYPE,'/etc/magic') And added in /etc/magic : Code: #------------------------------------------------------------------------------ Now detect all office documents. I check CI4 framework in system/Files/File.ph is function getMimeType() and don't have option for add custom magic file: PHP Code: /** mabye we can suggest to added that option? RE: docx file mime wrong type back getMimeType - JustJohnQ - 03-27-2023 There is a convo that this potentially is a bug in LibreOffice: https://bugs.documentfoundation.org/show_bug.cgi?id=101317 I don't see any reason why the mime type is changed after adding an image to a document. Allowing mime type 'application/octet-stream' sounds dangerous to me. |