How can the issue of a null byte appearing at the beginning of the downloaded file be resolved in a PHP SOCKS server implementation?

Issue: The null byte appearing at the beginning of the downloaded file in a PHP SOCKS server implementation can be resolved by trimming the null byte before saving the file.

// Trim null byte before saving the file
$fileContents = file_get_contents('php://input');
$fileContents = ltrim($fileContents, "\x00");

file_put_contents('downloaded_file.txt', $fileContents);