What are the potential security risks of setting chmod 777 for PHP uploads?

Setting chmod 777 for PHP uploads can pose a significant security risk as it gives full read, write, and execute permissions to everyone, including potential malicious users. This can lead to unauthorized access, execution of malicious scripts, and potential exploitation of the server. To mitigate this risk, it is recommended to set more restrictive permissions, such as 755, which only allows the owner to write and execute files.

// Set more restrictive permissions for PHP uploads
chmod($uploadFilePath, 0755);