What are the potential risks of allowing FTP users to upload PHP scripts on a server?

Allowing FTP users to upload PHP scripts on a server can pose a significant security risk as it opens the possibility for malicious code execution. To mitigate this risk, it is essential to validate and sanitize user input before allowing the uploaded PHP scripts to be executed on the server.

// Validate and sanitize the uploaded PHP file before allowing execution
$uploadedFile = $_FILES['file']['tmp_name'];

if (pathinfo($uploadedFile, PATHINFO_EXTENSION) !== 'php') {
    die('Invalid file type. Only PHP files are allowed.');
}

// Further validation and sanitization steps can be added here before executing the PHP script
include $uploadedFile;