X

Rate Us :



Share with Friends :

Menu

Configuration settings related to Files Upload :

$_FILES :

By using this super global variable we can get the information of uploaded files. It is two dimensional array variable providing five elements. Every element uses the complete information about uploaded file. Each element's first dimension is name of upload control.


If user upload any file from browser to server then firstly that file will upload into server temporary memory location. We need to implement server-side script to move that file from temporary memory location to permanent memory location. In temporary memory location it saves the file with another name.

Elements of $_FILES :

$_FILES contain five elements. Each element's first directory is name of the upload control.


$_FILES['nameofuploadcon']['size'] :

By using this element we can get uploaded file size in bytes.

X

bytes :

It refer to a group of binary digits or bits (1 byte = 8 bits) operated on as a unit.


$_FILES['nameofuploadcon']['name'] :

By using this element we can get uploaded file name.


$_FILES['nameofuploadcon']['type'] (MIME) :

By using this element we can get uploaded file type.


$_FILES['nameofuploadcon']['tmp_name'] :

By using this element we can get the temporary file name.


$_FILES['nameofuploadcon']['error'] :

By using this element we can get number of errors if any occurred at the time of file uploading.


MIME : 

(MIME stands for Multi-purpose Internet Mailing Extension)

It is a type of extension, used to transfer the files from one location to another location when user click on submit button. By default, form can transfer text format HTML data. If we want to transfer another format file, we need to specify MIME type of that file.


Some of the MIME types are :-

  • exe : application/octet-stream

  • jpg : image/jpeg

  • exe : application/pdf

<FORM> tag contains "enc" type attribute. By using this tag we can specify the MIME tag of input file.


multipart/form_data

This <MIME> tag supports any type of file.


is_uploaded_file($_FILES['fileupcon']['tmp_name']) :

By using this function we can check whether the file is uploaded from client system to server temporary location or not.


move_uploaded_file :

By using this we can move the uploaded file from temporary location to permanent location. It contains two arguments temporary file name and permanent location path.

Example :

<form method = "POST" action = "upload.php" enctype = "multipart/form_data"> <input type = "file" name = 'file1'> <br> <input type = "submit" value = 'send'> </form>

<?php if(is_uploaded_file($_FILES['file1']['tmp_name'])) { $fname = $_FILES['file1']['name']; if(move_uploaded_file($_FILES['file1']['tmp_name'],"uploads/$fname")) echo "File is moved"; else echo "Not moved"; } else echo "Not" ?>

Output :


File_uploads :

By using this configuration setting, we can allow and stop the file uploads. The default value is "ON". By changing this values as "OFF" we can stop the File_uploads.


upload_max_Filesize :

By using this configuration setting, we can specify the maximum file size to upload.


upload_tmp_dir :

By using this configuration setting, we can specify the temporary location for uploaded files. The default location is tmp folder.


$_FILES['uploadconname']['error'] :

By using this super global variable, we can get the error message if any occurred at the time of file upload. If the number of error is zero, file is uploaded successfully. If there is one error, file size is more than server configuration settings value. If there are two errors , file size is more than the browser configuration settings value. If there are three errors, there is some software problem at the time of file uploading. If there are four errors, user selected the submit button without any file selection.


$_SERVER :(Get server configuration setting)

By using this super global variable, we can get the information about server & browser. If we want to get server software, server IP address, browser IP address etc., we can go for $_SERVER.


$_SERVER['SERVER_SOFTWARE'] :

By using this we can get the software information what is available in Web server.


$_SERVER['SERVER_NAME'] :

By using this we can get the name of Web server.


$_SERVER['SERVER_ADDR'] :

By using this we can get the IP address of Web server.


$_SERVER['SERVER_PORT'] :

By using this we can get the port number of Web server. (By default port number is '80')


$_SERVER['REMOTE_ADDR'] :

By using this we can get the IP address of browser.


$_SERVER['DOCUMENT_ROOT'] :

By using this super global variable, we can get the document root of current application.


$_SERVER['SERVER_ADMIN'] :

By using this we can get the Admin_name@server_name.


$_SERVER['SCRIPT_FILENAME'] :

By using this we can get the current script name with complete script path.


$_SERVER['REMOTE_PORT'] :

By using this we can get the port number of browser.


$_SERVER['SERVER_PROTOCOL'] :

By using this we can get the protocol information what we are using to transfer the data.


$_SERVER['REQUEST_METHOD'] :

By using this we can get the method what we are using to transfer data with the browser and server.


$_SERVER['QUERY_STRING'] :

By using this we can get the query string value.


$_SERVER['REQUEST_URI'] :

By using this we can get the current script name with query string value.


$_SERVER['SCRIPT_NAME'] :

By using it's element we can get the currently executing script name.


$_SERVER['REQUEST_TIME'] :

By using this element we can get the time information of last request, as timestamp value.


$_SERVER[argv] :

By using this element we can get the total number of query string arguments.



Protocols :

A set of instruction to transfer the data between browser & server.

Protocols are divided into two types :-

  • Stateful protocols




  • Stateless protocols




Stateful protocols :

These protocols can maintain the state of application means we can access all the previous request and response values from current request. In Windows application we are using these protocols.

Example :

TCP/IP, FTP etc.


Stateless protocols :

These protocols cannot maintain the state of application means we cannot get the previous request and response values from current request. In Web application we are using these protocols because they don't carry the previous page values that's why the performance is very fast. The main drawback of stateless protocol is maintaining the state of application. To overcome this drawback state management concept was introduced.

Example :

http, https etc.