HTML文件表单,接受Word文档(HTML file form, accept Word documents)
我在这里遇到了一个奇怪的问题。 (不管怎样,或者我只是忽略了一些非常简单的东西。)
我有一个文件上传表单,我希望它只接受某些类型的文件,其中MS Word文档。 我将.doc和.docx MIME类型(分别为application/msword和application/vnd.openxmlformats-officedocument.wordprocessingml.document )添加到文件输入字段的accept属性中,但是当我点击“选择文件”时,。 doc和.docx文件仍然显示为灰色,因为不允许上传。
那么,我错过了什么? 任何帮助或指针将不胜感激!
(是的,我知道表单检查不是过滤上传文件的好方法。我有PHP覆盖,这对用户来说更方便,所以他们不去上传一个不允许的文件。)
I got a bit of a weird issue here. (Either that, or I'm just overlooking something stupidly simple.)
I have a file upload form, and I want it to only accept certain types of files amongst which MS Word documents. I added the .doc and .docx MIME-types (application/msword and application/vnd.openxmlformats-officedocument.wordprocessingml.document respectively) to the accept attribute of the file input field, yet when I hit "choose file", the .doc and .docx files are still greyed out as not allowed to be uploaded.
So, what am I missing? Any help or pointers would be greatly appreciated!
(And yes, I know the form-check isn't a good way to filter uploaded files. I've got PHP covering that, this is more of a convenience for the user, so they don't go and upload a disallowed file.)
原文:https://stackoverflow.com/questions/10487904
更新时间:2019-11-16 10:14
最满意答案
我是Word文件的MIME类型可能未在浏览器中注册,因此Word文件被报告为application/octet-stream 。 通常,HTML表单中的MIME类型过滤不能可靠地工作,除了常见的图像MIME类型。
您可以创建JavaScript解决方案来检查文件的扩展名。
I'm the MIME type for Word files likely isn't registered with the browser, so the Word file is being reported as application/octet-stream. In general, MIME type filtering in HTML forms does not work reliably, except for common image MIME types.
You could create a JavaScript solution to check the extension of the file.
相关问答
我是Word文件的MIME类型可能未在浏览器中注册,因此Word文件被报告为application/octet-stream 。 通常,HTML表单中的MIME类型过滤不能可靠地工作,除了常见的图像MIME类型。 您可以创建JavaScript解决方案来检查文件的扩展名。 I'm the MIME type for Word files likely isn't registered with the browser, so the Word file is being reported as a
...
https://github.com/PHPOffice/PHPWord PHPWord还具有一个可用于编辑现有文档的Reader。 https://github.com/PHPOffice/PHPWord PHPWord also features a Reader which can be used to edit existing documents.
您可以使用Word和Excel自动化 ,使用Visual Basic 6(通过COM ),VB .Net(通过interop )或C#(通过interop )等语言来完成此interop ,例如从数据库获取数据。 在你的情况下,因为你只是想创建一个基于Excel数据的文档,最简单的方法是使用MS Word 邮件的合并向导 。 看看: http : //office.microsoft.com/en-us/excel-help/print-labels-by-using-excel-data-in-
...
尝试之后,我设法将脚本记录到Python(使用Pywin32 )。 这导致下面的代码 from argparse import ArgumentParser, SUPPRESS, HelpFormatter
import datetime
from glob import glob
import os
import re
import subprocess
import sys
import win32com.client as win32
from win32com.client import
...
我们的团队使用Notifybox几个月来签出并签入Dropbox中的共享Excel和Word文件。 Notifybox的一些问题是它有时会错过文件打开和关闭,似乎阻止了Windows XP上的重新启动,有时错误地断定该PC上没有活动的Internet连接,即使Dropbox没有同步文件的问题,并且没有在Mac上运行。 我想出了一些简单的Visual Basic for Applications(VBA)宏来处理文件签出和签入。 我们一直在运行Office 2010和运行Office 2011的Ma
...
用于在Azure存储中编辑MS Word文档的选项 要在线编辑MS Word文档,将Word文档保存到OneDrive是一个不错的选择。 OneDrive将为我们上传的文件提供链接,我们可以根据此链接查看和编辑文件。 以下是详细步骤。 从Azure存储中读取要编辑的MS Word文档。 使用OneDrive API将此文档保存到OneDrive文件夹,并从响应中获取链接。 这是我用来将文件上传到OneDrive的HTTP请求消息。 PUT https://graph.microsoft.com/v
...
使用此选项使用内容获取图像首先创建一个.docx文件,然后在下一个文件中添加Html文档。 要使用AltChunk mathod,您必须使用创建的文件来创建文件动态首先使用默认内容创建,因为altChunk不接受空白文件。 1.使用较小的内容创建.docx文件。 2.在默认内容后添加html内容。 try
{strBody = "" + "
" + "using (MemoryS
...
Alias Word的Window类。 using WordWindow = Microsoft.Office.Interop.Word.Window;
using Window = System.Windows.Window;
然后更改使用Window from Word的位置以使用新别名WordWindow 。 它的一个例子: ...
using System.IO;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
us
...
您可以使用HTTP标头 <?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
echo "";
echo "";
...
您可以编写自己的事件接收器来收听Word应用程序的OnQuit事件。 但是,切换到早期绑定的COM会更容易。 Word2000.pas的导入类型库包含您需要的所有内容。 将TWordApplication用于您的应用程序对象。 将处理程序分配给应用程序对象的事件。 根据您想要做的事情,看起来最适用的事件是OnDocumentBeforeClose和OnQuit 。 为了说明,这是我可以设计的最简单的例子: uses
Word2000;
procedure TForm1.Button1Clic
...