What is the purpose of the "move_uploaded_file" function in PHP file uploads?
The "move_uploaded_file" function in PHP is used to move an uploaded file to a new location on the server. This function is commonly used after a file has been successfully uploaded using the "move_uploaded_file" function to store the file in a specific directory for further processing or storage.
$targetDirectory = "uploads/";
$targetFile = $targetDirectory . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}