$_FILES variable

The $_FILES Variables contains information regarding data uploaded to the server Via the POST method.

$_FILES variable Types :

$_FILES ['file-name']['name']: The name of the file as uploaded from the client To the server.

$_FILES ['file-name']['type']: This variable is used to which type of file has been move to server.

$_FILES['file-name']['size']: The byte size of the uploaded file.

$_FILES['file-name']['tmp_name']: When you upload a file from the form ,This files has been move to temp directory and then will move to server.

$_FILES['upload-name']['error']: An upload status code.

HTML Forms:

The Following form is used to upload file to server .

<form id="form1" name="form1" action="Upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload" id="file_upload">
<input type="submit" value="upload">
</form>

enctype="multipart/form-data"

we must use to encode type or "enctype" attribute File Upload Form otherwise file will not upload to server.

method="post"

File Upload From Post method will suport only .Get Method will not Support

PHP CODE :

Following Php Script Used to upload file to server.


<?php
$file_upload_folder_name = "uploads/";
$file_upload_target_path = $file_upload_target_path . basename( $_FILES['file_upload']['name']);
if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $file_upload_target_path))
{
echo "The file ". basename( $_FILES['file_upload']['name']). " has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}
?>

$file_upload_folder_name

This Variable we have assigned server folder name which is used to store the file.

$file_upload_target_path

This Variable we have assigned server Path name.

move_uploaded_file

This function used to Move the file to server.





Content