A Simple Form for Uploading a File A
A simple form for uploading a file
The enctype attribute of the form element is set to multipart/form-data this is required for file uploads to work. The enctype attribute specifies the encoding that should be used by the browser to encode the form parameters. The default value of enctype attribute is application/x-www-form-urlencoded:
This page will appear in the browser as: On receiving an HTTP request with input elements of type file, PHP stores the contents of the uploaded file in a temporary file. The temporary file is created in the server’s default temporary directory, unless another directory is specified by the upload_tmp_dir directive in the php.ini file. The server’s default temporary directory can be changed by setting the environment variable TMPDIR. The temporary file is deleted at the end of the request, so the PHP script handling the request should copy the file if the file data is to be preserved for later use. The details of the uploaded file are accessible to PHP scripts through a two-dimensional global array HTTP_POST_FILES. Supposing that the name of the input element (of type file) is userfile, then: . The variable $HTTP_POST_FILES[ userfile ][ name ] contains the original name of the file on the client machine . The variable $HTTP_POST_FILES[ userfile ][ type ] contains the mime type of the file . The variable $HTTP_POST_FILES[ userfile ][ size ] contains the size, in bytes, of the uploaded file . $HTTP_POST_FILES[ userfile ][ tmp_name ] contains the temporary filename of the file in which the uploaded file was stored on the server Below is a PHP script, upload.php, which copies the uploaded file to the temp/ directory:
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra servlet hosting services