$_FILES :

$_FILES : This super global Variable is used to handle File uploading in Server 

Files can be of Any Type

1. Binary 

2. Non Binary File


Example of Binary

Media Files mp3,mp4,pdf,zipped,or any other MIME Type

Example of Non Binary

All text format Files are Non Binary Files

.tmp

.log

.txt

.dat

.doc

.csv

.html Non Binary

.xml Non Binary


Uploading Means :

Read from One source and write One Another Source Read from One Destination and Write to Another Destination.


Copy and Move

Copy : first create the File

   Read the from 1 File

   write Another 2-File

   Memory Release of File Pointer

   

In C Langauge

File* fp1;

File* fp2;

fp1=&File;

fp2=&File;

fp1=fopen("c:/something.txt",r);

fp2=fopen("d:/something.txt",w);

while($ch=fread(fp1)!=EOL){

fwrite(fp2,$ch)

}

fclose(fp1);

fclose(fp2);


Move :

Copy : first create the File

   Read the from 1 File

   write Another 2-File

   Memory Release of File-2 Pointer

   fseek(-1)

   

Steps How to upload files on server

Internal Working:

When ever we try to upload any file the a upload request is generated and file pointer is intialised


Who Intialised the File Pointer : 

Inbuilt Server is Responsible for Intialising the File Pointer

1. Apache 

2. PHP Cli Server


By default file pointer has source Address of tmp folder location in server

folder of Any server

Apache : tmp Root

php Inbuilt Server  : php tmp folder


What is this tmp folder

it is default folder where every file handling is performed by server like storing file based session by file name sess_....

2. using any file with .tmp extension


Such path is defined inside php.ini file

Now the file which is to be uploaded from browser required key parameters

1. file_uploads=on in ini setting of server

2. Path should be available to tmp folder

   upload_tmp_dir=

 define the path 

 

Note : in ini files ; means disable to enable directive remove ;

in httpd.conf # means disabled to enable #remove hash



3. file uploading in browser is now ready 

steps for code

----------------

<form method="post" enctype="multipart/form-data">

<input type="file" name="xyz..">

<input type="submit">


Server Side Code

print_r($_FILES);

It is two dimensional

name key : name of file

tmp_name : file address of tmp folder

error : it show the error if happend during upload

size: it give the total memory reserved by tmp file

type : mime Type



Validating File Uploads

------------------------

Loop Hole : error is used to detect Error but this error is related to processing or Illegal Error But not valid or used defined error.

$filename = $_FILES['keyname']['name'];

$error = $_FILES['keyname']['error'];  #Processing Error


Working with $_FILES Super Global Varible