What are the potential consequences of not setting the correct file permissions when working with files in PHP?

If file permissions are not set correctly when working with files in PHP, it can lead to security vulnerabilities such as unauthorized access, modification, or deletion of files. To solve this issue, it is important to set appropriate file permissions to ensure that only authorized users can access or modify the files.

// Set file permissions to 0644 for files and 0755 for directories
chmod("/path/to/file.txt", 0644);
chmod("/path/to/directory", 0755);