I had a few files containing email attachments that needed to be converted into usable files. The following code (which has no checks in it), did the trick: <?php function decode_email_attachment(){ $data= file_get_contents($inputfile); file_put_contents($outputfile, base64_decode(str_replace( “\r\n”, “”, $data ))); } ?>