What are potential reasons for the move_uploaded_file function not moving files to the specified directory in PHP?

The move_uploaded_file function may not be moving files to the specified directory due to incorrect file permissions, incorrect directory path, or insufficient server resources. To solve this issue, ensure that the destination directory has the correct permissions for file uploads, double-check the directory path provided in the function, and make sure that the server has enough resources to handle file uploads.

$target_directory = "uploads/";
$target_file = $target_directory . basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "File uploaded successfully.";
} else {
    echo "Error moving file to specified directory.";
}