What permissions are required for PHP to upload files?

In order for PHP to upload files, the directory where the files are being uploaded to must have the correct permissions set. The directory needs to have write permissions enabled so that PHP can save the uploaded files to that location. This can typically be done by setting the directory permissions to 755 or 777, depending on the level of security needed.

// Set the directory where files will be uploaded
$upload_dir = 'uploads/';

// Check if the directory exists, if not create it
if (!file_exists($upload_dir)) {
    mkdir($upload_dir, 0777, true);
}

// Set the correct permissions for the upload directory
chmod($upload_dir, 0777);