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

  • Home
  • SEARCH
  • 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 6972883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:01:55+00:00 2026-05-27T17:01:55+00:00

I want to base 64 encode uploaded file then save this into Blob type

  • 0

I want to base 64 encode uploaded file then save this into Blob type column of a table in MySQL database.

I have tried built in PHP function base64_encode with file variable but this does not seem to work.

Is there a way we can do this?

The reason is that I do not want to use moveuploaded file into a folder.

Thank you.

  • 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-27T17:01:56+00:00Added an answer on May 27, 2026 at 5:01 pm

    As @Sjoerd and @zerkms correctly point out, you do not need to do this – a blob column is be used to store raw binary data, so you can bypass the Base64 process and insert the raw data of the file.

    If you want to store images in a database (which, by the way, I personally don’t like to do) it is better to store the raw data – Base64 encoding the data makes it larger, and means that it must be decoded before the image is rendered, which adds processing overhead.

    This is how you can insert the raw binary data (assuming the MySQL extension):

    $data = file_get_contents($_FILES['name_of_control']['tmp_name']);
    $data = mysql_real_escape_string($data);
    
    $query = "
      INSERT INTO table
        (`blob_column`)
      VALUES
        ('$data')
    ";
    
    mysql_query($query);
    

    If you really do want to Base64 encode it (in which case it could just be stored in a varchar), just just add a base64_encode() call:

    $data = file_get_contents($_FILES['name_of_control']['tmp_name']);
    $data = base64_encode($data);
    
    // There is an argument that this is unnecessary with base64 encoded data, but
    // better safe than sorry :)
    $data = mysql_real_escape_string($data);
    
    $query = "
      INSERT INTO table
        (`varchar_column`)
      VALUES
        ('$data')
    ";
    
    mysql_query($query);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to base-64 encode a PNG file, to include it in a data:url
I want v0.1.27 of nodejs code base. This is what I did. git clone
I have an array of bytes (any length), and I want to encode this
I want to encode a file it may be image or any pdf and
So I'm writing a framework on which I want to base a few apps
I have a ListView. If I want to base the html markup on a
I want to get the base 10 logarithm of a Fixnum using Ruby, but
I want to have a base class which dictates the alignment of the objects
I want to know what a virtual base class is and what it means.
I want to create templates for base new reports on to have common designs.

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.