[英]PHP upload file using PUT instead of POST
I read something about this on PHP docs , but it's not clear to me: 我在PHP文档中读到了一些关于此的内容,但我不清楚:
Do the most widely used browsers (IE, FF, Chrome, Safari, Opera, ...) support this PUT
method to upload files? 最广泛使用的浏览器(IE,FF,Chrome,Safari,Opera等)是否支持此
PUT
方法上传文件?
What HTML should I write to make the browser call the server via a PUT
request? 我应该写什么HTML来让浏览器通过
PUT
请求调用服务器? I mean do I need to write a FORM
with an INPUT
file field and just replace the attribute method="POST"
with method="PUT"
? 我的意思是我需要用
INPUT
文件字段写一个FORM
,然后用method="PUT"
替换属性method="POST"
method="PUT"
吗?
On the PHP docs (link above) they say a PUT
request is much simpler than a POST
request when uploading file, along with this advantage, what other advantages/disadvanatges do the PUT
has got compared to the POST
? 在PHP文档(上面的链接)上,他们说
PUT
请求比上传文件时的POST
请求要简单得多,还有这个优势, PUT
与POST
相比还有哪些其他优点/缺点?
The PUT method cannot be used from a <form>. 无法从<form>中使用PUT方法。 MSIE does not support it through the user GUI at all.
MSIE根本不支持通过用户GUI。 You can however use XMLHttpRequest .
但是,您可以使用XMLHttpRequest 。 It seems to be defined in the standard and WHATWG / HTML5.
它似乎在标准和WHATWG / HTML5中定义。 My browser (Opera) obviously likes it.
我的浏览器(Opera)显然喜欢它。
http://old.mnot.net/javascript/xmlhttprequest/ IE might work too, as a short Google search suggests. http://old.mnot.net/javascript/xmlhttprequest/ IE也可能会起作用,就像谷歌的简短搜索所暗示的那样。 And Firefox looks fine.
Firefox看起来很好。 Not checked Chrome or Webkit.
未检查Chrome或Webkit。
Server-site you need a specially designated script to handle an incoming PUT request. 在服务器站点,您需要一个特殊指定的脚本来处理传入的PUT请求。 Look into the Apache docs.
查看Apache文档。 A mod_rewrite rule might usually do.
mod_rewrite规则通常可以这样做。 The genral adavantage of PUT is that there is no file encoding / marshalling into a multipart/* mime type required.
PUT的一般优点是没有文件编码/编组成所需的multipart / * mime类型。 In theory this allows uploading larger files more reliably.
理论上,这允许更可靠地上传更大的文件。 Allthough if you use PHP, it won't help you much.
尽管如果你使用PHP,它对你没有多大帮助。 It's meant for Webservers with WebDAV support and/or direct filesystem write access.
它适用于具有WebDAV支持和/或直接文件系统写访问的Web服务器。 (Apache can save uploaded files itself, if you use that.)
(如果您使用Apache,Apache可以自行保存上传的文件。)
I think the method is supported by most major browsers, but you can't account for every browser and other client that is out there. 我认为这种方法得到了大多数主流浏览器的支持,但你无法解释那里的每个浏览器和其他客户端。 From a cursory look at the user contributed notes, this sometimes even needs server-side configuration to work.
从粗略看一下用户提供的注释,有时甚至需要服务器端配置才能工作。
Also, handling any additional form values you may want to send along with your file becomes more difficult. 此外,处理您可能希望与文件一起发送的任何其他表单值变得更加困难。
I wouldn't use it. 我不会用它。 Way too much possible hassle for little actual gain.
方式太多可能为实际收益带来麻烦。
PUT
没有被浏览器广泛支持,并且通常不用于交互式HTML表单。
PUT
很少用于此目的且仅受主要浏览器支持的事实将其排除在此处的任何可能用途之外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.