PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variable i.e. $_FILES, it contains all information about file.By the help of $_FILES global variable, we can get file name, file type, file size and temparary file name associated with file.
In HTML, File Upload control can be created by using following:
In PHP, To upload the file we have to use the function called move_uploaded_file().
The move_uploaded_file() function is used to move the uploaded file to a new location. It moves the file only if it is uploaded through the POST request.
Syntax:
move_uploaded_file ( string $filename , string $destination )
php.iniFile by ensure that PHP is configured to allow file uploads. In your
php.inifile, search for the file_uploads directive, and set it to
Oni.e. file_uploads = On
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
Select File: <input type="file" name="fileToUpload"/>
<input type="submit" value="Upload Any File" name="submit"/>
</form>
<?php
if(isset($_POST["submit"]))
{
$target_path = "D:/";
$target_path=$target_path.basename($_FILES['fileToUpload'] ['name'] );
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path))
{
echo "File uploaded successfully!";
}
else
{
echo "Sorry, file not uploaded, please try again!";
}
}
?>
</body>
</html>