How can one ensure that uploaded files are stored in the correct directory when using PHP?

When uploading files using PHP, it is important to specify the correct directory where the files should be stored. This can be achieved by setting the "move_uploaded_file" function to move the uploaded file to the desired directory. Make sure to provide the correct path to the directory where you want the files to be stored.

$uploadDir = 'uploads/'; // specify the directory where files should be stored
$uploadedFile = $uploadDir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadedFile)) {
    echo "File uploaded successfully.";
} else {
    echo "Error uploading file.";
}