PHP FILE UPLOAD
- It is easy to upload files to the server.
- However, with ease comes danger, so always be careful when allowing file uploads.
- Configure The "php.ini" File. First, ensure that PHP is configured to allow file uploads.
- Check if File Already Exists. Now we can add some restrictions
- Limit File Size. The file input field in our HTML form above is named "fileToUpload".
- Limit File Type.
- Complete Upload File PHP Script.
EXAMPLE FOR FILE UPLOAD IN PHP :
<!DOCTYPE html>
<html>
<body>
<?php
$target_dir = "php_examples/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "The file has been successfully uploaded.";
}
else
{
echo "File not uploaded. Something is Wrong";
}
}
?>
</body>
</html>
OUTPUT :
The file has been successfully uploaded.