What are the implications of setting directory permissions to 777 in a PHP script for uploading files?

Setting directory permissions to 777 in a PHP script for uploading files can pose a security risk as it allows anyone to read, write, and execute files in that directory. To mitigate this risk, it is recommended to set more restrictive permissions, such as 755, which allows the owner to read, write, and execute files, while others can only read and execute.

// Set directory permissions to 755
$directory = 'uploads/';
if (!file_exists($directory)) {
    mkdir($directory, 0755, true);
}