xm2c7g
Last Updated: February 25, 2016
·
861
· rican7

Creating base64 test files

I was in the process of writing and testing a FileObject class in PHP for abstracting file handling, and I needed a file for testing base64 decoding.

Sooo, after downloading an image for testing, I created a couple of base64 encoded versions for testing. Like so:

At a bash prompt, simply run:

cat photo.jpg | base64 > photo.base64

Alternatively, run it through PHP:

cat photo.jpg | php -r 'echo base64_encode(file_get_contents("php://stdin"));' > photo.base64

Finally, to get a "chunked" version to conform to RFC 2045:

cat photo.base64 | php -r 'echo chunk_split(file_get_contents("php://stdin"));' > photo.chunked.base64

Boom, now I have useful test files. :)

(make sure to run each of these on one line... they're line wrapping, thanks to Coderwall's CSS)