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"][chunked] version to conform to [RFC 2045][rfc]:
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)
[chunked]: http://php.net/manual/en/function.chunk-split.php
[rfc]: http://www.ietf.org/rfc/rfc2045.txt
Written by Trevor N. Suarez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#