草庐IT

关于 php:MIME 类型 XLSX(来自 LibreOffice)

codeneng 2023-03-28 原文

MIME type XLSX (from LibreOffice)

我正在尝试解决一个问题:我想将 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 类型错误

有关关于 php:MIME 类型 XLSX(来自 LibreOffice)的更多相关文章

  1. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  2. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

  3. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

  4. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  5. ruby-on-rails - 在 Rails 开发环境中为 .ogv 文件设置 Mime 类型 - 2

    我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain

  6. ruby - 可以正常中断的来自 Rake 的长时间运行的 shell 命令? - 2

    在几个项目中,我希望有一个类似rakeserver的rake任务,它将通过任何需要的方式开始为该应用程序提供服务。这是一个示例:task:serverdo%x{bundleexecrackup-p1234}end这行得通,但是当我准备停止它时,按Ctrl+c并没有正常关闭;它中断了Rake任务本身,它说rakeaborted!并给出堆栈跟踪。在某些情况下,我必须执行Ctrl+c两次。我可能可以用Signal.trap写一些东西来更优雅地中断它。有没有更简单的方法? 最佳答案 trap('SIGINT'){puts"Yourmessa

  7. ruby-on-rails - 关于 Ruby 的一般问题 - 2

    我在我的rails应用程序中安装了来自github.com的acts_as_versioned插件,但有一段代码我不完全理解,我希望有人能帮我解决这个问题class_eval我知道block内的方法(或任何它是什么)被定义为类内的实例方法,但我在插件的任何地方都找不到定义为常量的CLASS_METHODS,而且我也不确定是什么here,并且有问题的代码从lib/acts_as_versioned.rb的第199行开始。如果有人愿意告诉我这里的内幕,我将不胜感激。谢谢-C 最佳答案 这是一个异端。http://en.wikipedia

  8. ruby - ruby 中的同一个程序如何接受来自用户的输入以及命令行参数 - 2

    我的ruby​​脚本从命令行参数获取某些输入。它检查是否缺少任何命令行参数,然后提示用户输入。但是我无法使用gets从用户那里获得输入。示例代码:test.rbname=""ARGV.eachdo|a|ifa.include?('-n')name=aputs"Argument:#{a}"endendifname==""puts"entername:"name=getsputsnameend运行脚本:rubytest.rbraghav-k错误结果:test.rb:6:in`gets':Nosuchfileordirectory-raghav-k(Errno::ENOENT)fromtes

  9. ruby-on-rails - Rails 3,在RAILS_ROOT上方显示来自本地文件系统的jpg图片 - 2

    我正在尝试找出一种方法来显示来自不在RAILS_ROOT下(在RedHat或Ubuntu环境中)的已安装文件系统的图像。我不想使用符号链接(symboliclink),因为这个应用程序实际上是通过Tomcat部署的,而当我关闭Tomcat时,Tomcat会尝试跟随符号链接(symboliclink)并删除挂载中的所有图像。由于这些文件的数量和大小,将图像放在public/images下也不是一种选择。我查看了send_file,但它只会显示一张图片。我需要在一个格式良好的页面中显示6个请求的图像。由于膨胀,我宁愿不使用Base64编码,但我不知道如何将图像数据与呈现的页面一起传递下去。

  10. ruby-on-rails - Rails 迁移中的 PostgreSQL 点类型 - 2

    我想使用PostgreSQL中的point类型。我已经完成了:railsgmodelTestpoint:point最终的迁移是:classCreateTests当我运行时:rakedb:migrate结果是:==CreateTests:migrating====================================================--create_table(:tests)rakeaborted!Anerrorhasoccurred,thisandalllatermigrationscanceled:undefinedmethod`point'for#/hom

随机推荐