我正在尝试解决一个问题:我想将 XLS/XLSX 文件上传到我的网站。而且我有这个条件:

1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }

当我使用 XLS/X 文件(直接从 MS Excel 中保存)时,效果很好。但是当我想上传 XLS/X 文件时——它直接从 LibreOffice 保存(不是作为 ODS,而是作为 XLS/X)——它不起作用,我无法上传这个文件。

感谢您的帮助!

(并且 application/vnd.oasis.opendocument.spreadsheet 的条件也不起作用。)

更新:感谢 Dipanwita Kundu,我能够找到使用了哪种 MIME 类型 ( application/octet-stream ) – 但是将其作为条件是否安全?



相关讨论

  • 尝试使用 `’application/vnd.openxmlformats-officedocument.spreadsheetm??l.sheet’,’application??n/vnd.openxmlformats??-officedocument.word??processingml.documen??t’
  • 嗨,谢谢 – 但没有任何效果,它仍然无法正常工作。
  • 尝试打印您的 mime 内容类型,我的意思是 echo mime_content_type($file)
  • 试试这个

    1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ || mime_content_type ( $file ) == ‘application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }

    434511

    如果您使用 LibreOffice Calc 保存文件,则 php mime_content_type($file) 返回值为 \\’application/zip\\’。

    使用 codeigniter 上传 xls 或 xlsx 文件,mime 类型错误

  • 试试这个

    1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ || mime_content_type ( $file ) == ‘application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }

    434511

    如果您使用 LibreOffice Calc 保存文件,则 php mime_content_type($file) 返回值为 \\’application/zip\\’。

    使用 codeigniter 上传 xls 或 xlsx 文件,mime 类型错误

  • 试试这个

    1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ || mime_content_type ( $file ) == ‘application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }

    434511

    如果您使用 LibreOffice Calc 保存文件,则 php mime_content_type($file) 返回值为 \\’application/zip\\’。

    使用 codeigniter 上传 xls 或 xlsx 文件,mime 类型错误

  • 试试这个

    1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ || mime_content_type ( $file ) == ‘application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }

    434511

    如果您使用 LibreOffice Calc 保存文件,则 php mime_content_type($file) 返回值为 \\’application/zip\\’。

    使用 codeigniter 上传 xls 或 xlsx 文件,mime 类型错误


试试这个

1 if ( ( mime_content_type ( $file ) == ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ || mime_content_type ( $file ) == ‘application/vnd.ms-excel’ || mime_content_type ( $file ) == ‘application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet’ ) && ( $extension == ‘xls’ || $extension == ‘XLS’ || $extension == ‘xlsx’ || $extension == ‘XLSX’ ) ) { upload }



相关讨论

  • 嗨,谢谢你的努力 :) 但它不起作用:( (在此之前它没有给我写任何错误(只是”我的”消息,它不支持的文件),现在有了你的解决方案,它写给我:’警告:mime_content_type():只能在第 124 行的 /data/web/virtuals/25/virtual/www/subdom/avcr/vrstvy/upload.??php 中处理字符串或流参数。


如果您使用 LibreOffice Calc 保存文件,则 php mime_content_type($file) 返回值为 \\’application/zip\\’。

使用 codeigniter 上传 xls 或 xlsx 文件,mime 类型错误


声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。