Is it possible to display the file path as a link after a successful upload in PHP?

To display the file path as a link after a successful upload in PHP, you can simply echo out the file path as an anchor tag within the success message. This way, users can click on the link to access the uploaded file. You can also set the target attribute of the anchor tag to "_blank" to open the link in a new tab.

<?php
if ($_FILES["file"]["error"] == 0) {
    $uploadDir = "uploads/";
    $filePath = $uploadDir . $_FILES["file"]["name"];
    
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $filePath)) {
        echo "File uploaded successfully. <a href='$filePath' target='_blank'>View File</a>";
    } else {
        echo "Error uploading file.";
    }
} else {
    echo "Error: " . $_FILES["file"]["error"];
}
?>