How can PHP move uploaded files to specific folders automatically?

To automatically move uploaded files to specific folders in PHP, you can use the move_uploaded_file() function. This function takes the temporary file path of the uploaded file and the destination path where you want to move the file. You can determine the destination folder based on certain conditions or parameters in your code.

$uploadDir = 'uploads/'; // Specify the upload directory
$uploadedFile = $_FILES['file']['tmp_name']; // Get the temporary file path
$destination = $uploadDir . $_FILES['file']['name']; // Set the destination path

if(move_uploaded_file($uploadedFile, $destination)) {
    echo "File moved successfully to " . $destination;
} else {
    echo "Failed to move file.";
}