views:

262

answers:

4

I read something about this on PHP docs, but it's not clear to me:

  1. Do the most widely used browsers (IE, FF, Chrome, Safari, Opera, ...) support this PUT method to upload files?

  2. What HTML should I write to make the browser call the server via a PUT request? I mean do I need to write a FORM with an INPUT file field and just replace the attribute method="POST"with method="PUT"?

  3. 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?

A: 

PUT is not very widely supported by browsers, and isn't generally used for interactive HTML forms.

Amber
+1  A: 

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.

Pekka
@Pekka: thanks for yiur suggestion. In PHP website here there is a community comment explaining exactly how to do it on the server, it does not seem a huge effort it rquires only to set up a bit the .htaccess file. What the commentor misses ids the way to do it on the client browser.
Marco Demajo
@Marco on client side, it should be a simple `<form method='PUT'>`. (Update: According to @Mario, this is not enough. Check his answer.) But as I said, while the major browsers support it, many many client libraries, components, exotic browsers, and other clients may not.
Pekka
A: 

The fact that PUT is rarely used for the purpose and only supported by major browsers excludes it from the any possible use here.

Sarfraz
+2  A: 

The PUT method cannot be used from a <form>. MSIE does not support it through the user GUI at all. You can however use XMLHttpRequest. It seems to be defined in the standard and WHATWG / HTML5. My browser (Opera) obviously likes it.

http://old.mnot.net/javascript/xmlhttprequest/ IE might work too, as a short Google search suggests. And Firefox looks fine. Not checked Chrome or Webkit.

Server-site you need a specially designated script to handle an incoming PUT request. Look into the Apache docs. A mod_rewrite rule might usually do. The genral adavantage of PUT is that there is no file encoding / marshalling into a multipart/* mime type required. In theory this allows uploading larger files more reliably. Allthough if you use PHP, it won't help you much. It's meant for Webservers with WebDAV support and/or direct filesystem write access. (Apache can save uploaded files itself, if you use that.)

mario