File Upload in PHP

File upload in php. uploading files to a server is a simple process. PHP makes it easier to upload files to a server by providing some unique features. PHP allows you to upload single or multiple files with ease. PHP allows you to upload both binary and text files. Other functions and methods in PHP can be used to check and control the features associated with file uploading, such as determining the file size and type, or moving the uploaded file to a new location.

PHP move_uploaded_file() Function

To move an uploaded file to a new location, use the PHP move uploaded file() function. The PHP move uploaded file() function only moves files that have been uploaded via HTTP POST. 

The PHP move uploaded file() function either creates a new file or overwrites an existing file at the destination. If the file is successfully moved, the PHP move uploaded file() function returns TRUE; otherwise, it returns FALSE if the process of moving the uploaded file to a new destination fails.

<!DOCTYPE html>
<html>
<body>
<?php
$target_dir = "php_programs/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "The file uploaded";
}
else
{
echo "File not uploaded";
}
}
?>
</body>
</html>

 

Output:

The file uploaded

PHP.ini File

The php. ini file is a PHP-specific file. It’s where you declare modifications to your PHP configuration. The server is already set up with normal PHP settings, which your site will use by default. There is no need to build or alter a php unless you need to update one or more settings.

If Else Statement in PHP

The IF statement is a decision-making statement that directs a program’s decisions based on predefined criteria. The IF statement runs one set of code if a specified condition is met (TRUE) or another set of code if the condition is not met (FALSE). If a specified condition is true, the if/else statement executes a block of code.

If the condition is not met, another block of code can be run. The if/else statement is a type of “Conditional” Statement in JavaScript, which is used to perform different actions based on different conditions.