What are the security implications of using chmod 777 for file permissions in PHP?

Using chmod 777 for file permissions in PHP is not recommended as it gives full read, write, and execute permissions to everyone, including potentially malicious users. This can lead to security vulnerabilities such as unauthorized access, data breaches, and code execution. It is best practice to set more restrictive permissions based on the principle of least privilege.

// Set file permissions to 644
$filename = 'example.txt';
chmod($filename, 0644);