Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 713711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:59:29+00:00 2026-05-14T04:59:29+00:00

I have a binary that I want to convert to standard MIME-compliant base64 string.

  • 0

I have a binary that I want to convert to standard MIME-compliant base64 string. I thought I could use the php://filter method to filter the stream, but I’m getting hung up on how to set the "line-length" parameter. There are other methods that would achieve similar results, but I’m trying to figure out if:

  1. If it’s even possible/allowed to set parameters for stream filters using the URI-style method.

  2. How it is done, if it is possible.

Here are the pieces to the puzzle I’ve got so far:

Obviously, I could stop trying to be fancy and simply 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 php://filter method without the line-length parameter and split it afterward:

$binary = "path/to/binary.file";
$mime = file_get_contents("php://filter/read=convert.base64-encode/resource=$binary");
$mime = chunk_split($mime);

Or, I can use fopen combined with stream_filter_append and not use the URL-style at all (as documented in the Conversion Filters manual):

$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);

So all of the above give the same result, but none of them are what I was hoping for, which was to add the line-length parameter in the same URL for the stream. Something maybe like:

$mime = file_get_contents("php://filter/read=convert.base64-encode:line-length=76/resource=$binary");

I imagine the issue is that the parameter has to be passed as an array when stream_filter_append is used.

So does anyone know if what I want can be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:59:30+00:00Added an answer on May 14, 2026 at 4:59 am
    1. If it’s even possible/allowed to set parameters for stream filters using the URI-style method.

    Unfortunately, currently, it is not possible1 to provide anything other than the filter name (in your case convert.base64-encode) for those php://filter URLs.

    I would go with your stream_filter_append approach, substituting stream_get_contents for fread(...).

    1. See the current source which explicitly uses NULL for the filterparams parameter to php_stream_filter_create. It wouldn’t2 be too much work to implement reading of arguments of the style you suggested.
    2. I am not a C programmer.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you have binary strings (literally String objects that contain only 1's and 0's),
Lets say I have some binary value: 0b100 and want to convert it to
I have a binary file that I have to parse and I'm using Python.
I have binary data in a file that I can read into a byte
I have a binary field in my database that is hard to describe in
I have a simulation that reads large binary data files that we create (10s
I have a class that I need to binary serialize. The class contains one
We have an HttpHandler that deals directly with binary posts over HTTP from custom
If you have binary data that you need to encode, what encoding scheme do
I want to generate a binary mask that has ones for all voxels inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.