I have a binary that I want to convert to a standard base64 string compatible with MIME. I thought I could use a method php://filterto filter the stream, but I get a hang on how to set the "lengths". There are other methods that would achieve similar results, but I'm trying to find out if:
Even if it is possible / allowed to set parameters for stream filters using the URI-style method.
How to do it, if possible.
Here are the pieces of the puzzle that I still have:
Obviously, I could stop trying to be fantasy and just go with:
$binary = "path/to/binary.file";
$mime = file_get_contents($binary);
$mime = base64_encode($mime);
$mime = chunk_split($mime);
Or I can use the method php://filterwithout a parameter line-lengthand split it later:
$binary = "path/to/binary.file";
$mime = file_get_contents("php://filter/read=convert.base64-encode/resource=$binary");
$mime = chunk_split($mime);
fopen stream_filter_append URL ( ):
$binary = "path/to/binary.file";
$param = array('line-length' => 76, 'line-break-chars' => "\r\n");
$fp = fopen($binary, 'r');
stream_filter_append($fp, 'convert.base64-encode',null, $param);
$mime = fread($fp, filesize($binary));
fclose($fp);
, , , , line-length URL- . - :
$mime = file_get_contents("php://filter/read=convert.base64-encode:line-length=76/resource=$binary");
, , , stream_filter_append.
- , , , ?