What are the advantages and disadvantages of using input type text instead of input type file for file upload in PHP?

Using input type text instead of input type file for file upload in PHP has the advantage of allowing for custom file names and paths to be specified by the user. However, this method lacks the built-in file validation and security features provided by input type file, making it more susceptible to malicious file uploads. It is important to implement thorough validation and sanitization measures when using input type text for file uploads to ensure the security of the application.

// Example of implementing file upload using input type text
if(isset($_POST['submit'])){
    $file_name = $_POST['file_name'];
    $file_path = 'uploads/' . $file_name;

    // Validate file extension and content type before saving the file
    // Implement additional security measures to prevent malicious file uploads

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