Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP file uploads. POST vs PUT?

I am building a website where people can upload video with the file size restriction of 1GB. Firefox>3.6 and Chrome>11 are the only browsers i intend to support. Is there any advantage/disadvantage of file uploads using PUT method over POST method for huge files. How does different http methods affect the performance of the website?

like image 230
Vipin Parakkat Avatar asked Jun 28 '11 18:06

Vipin Parakkat


People also ask

How does PHP file upload work?

A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script. The user opens the page containing a HTML form featuring a text files, a browse button and a submit button.

Why do we need to specify method post during file upload?

Set the method attribute to POST because file content can't be put inside URL parameters. Set the value of enctype to multipart/form-data because the data will be split into multiple parts, one for each file plus one for the text data included in the form body (if text is also entered into the form).

What is Tmp_name in PHP file upload?

tmp_name is the temporary name of the uploaded file which is generated automatically by php, and stored on the temporary folder on the server. name is the original name of the file which is store on the local machine.

Which HTTP method is used for file upload?

HTTP Request action allows you to upload files on a specified service.


1 Answers

I have no personal opinion on this matter but here are some resources that may help you:

  • http://www.elharo.com/blog/software-development/web-development/2005/12/08/post-vs-put/

PUT is a much more limited operation that never does anything more than PUT one page at a specified URL. It is idempotent, which is a fancy way of saying that doing it twice is the same as doing it once. Both PUT and POST can be used to create new pages. However PUT should be used when the client specifies the location for the page. PUT is normally the right protocol for a web editor like DreamWeaver or BBEdit. POST is used when the client gives sends the page to the the server, and the server then tells the client where it put it. POST is normally the right protocol for a blog editor like TypePad or anything that inputs into a content management system. In SQL analogy, POST is an INSERT with an automatically generated primary key, and PUT is an INSERT that specifies the primary key in the INSERT statement.

  • PUT vs. POST for files upload RESTful api to be built using Zend Framework
  • PUT vs POST in REST
  • http://upload.thinfile.com/docs/put.php

    The PUT method, though not as widely used as the POST method is perhaps the more efficient way of uploading files to a server. This is because in a POST upload the files neede to be combined together into a multipart message and this message has to be decoded at the server. In contrast, the PUT method allows you to simply write the contents of the file to the socket connection that is established with the server.


From my understanding of reading the above links, skimming over the mains sections tells me that PUT methods are mainly used for raw data with no organization to the content, there not encoded or split into multi part messages.

PUT seems like Socket to Socket connection such as Telnet <> Mail Server, so using POST may provide more of an underlying framework to uploading multiple files in a single batch, as you already have the boundaries built in my the POST method

like image 170
RobertPitt Avatar answered Oct 23 '22 00:10

RobertPitt