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 8616833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:42:45+00:00 2026-06-12T05:42:45+00:00

So I send the base64 image text to the php file with jquery/javascript like

  • 0

So I send the base64 image text to the php file with jquery/javascript like this:

//Upload picture
$('#uploadPictureBtnHtml').click(function(){
    OpenLoader();
   var baseEncPicData = $('#chosenPictureData').val();
    $.ajax({
        type:'POST', url:'upload_picture.php',  dataType:"json",  data:{ PicFile: baseEncPicData },
        success:function (upload_pic_data) {
            if (upload_pic_data[0] == 'true') {
                    alert("it worked!");
                    CloseLoader();
            }
            else{
                    //upload_pic_data[1] will return PHP errors
                    alert("Why it didnt work: "+upload_pic_data[1]+" ");
                    CloseLoader();
            }
        }
        });
});

I know this works fine because if I take the baseEncPicData variable and output it like this:

$('#some_div').html('<img src="data:image/jpeg;base64,'+baseEncPicData+'" />');

It works just great and the image shows without an issue.

When I send this to the PHP file, I decode and “reassemble” it like this:

$dataUno = htmlspecialchars(trim(urldecode($_POST['PicFile'])));
$dataDos = base64_decode($dataUno);
$data = imagecreatefromstring($dataDos);
$the_new_png = imagepng($data, $the_directory);

The error I receive is only in PHP which is:

 imagecreatefromstring() [function.imagecreatefromstring]: Empty string or invalid image
 imagepng() expects parameter 1 to be resource

Which leads me to believe that it’s not decoding the JSON correctly because there are characters being stripped that are part of the base64’d image. This is just an assumption.
Not exactly sure what I’m doing wrong. Any help would be awesome. Thanks for taking your time to read this.

  • 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-06-12T05:42:47+00:00Added an answer on June 12, 2026 at 5:42 am

    Remove this string:

    htmlspecialchars(trim(urldecode($_POST['PicFile'])));

    … and process just $_POST['PicFile'] instead. With that preprocessing you turn all + characters (allowed in Base64) into spaces (), effectively broking the binary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which send an image to test.php: chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.captureVisibleTab(null, function(img)
I'm trying to send an image as a Base64 encoded string to my PHP
I want to send base64 string through ajax I encoded it through JavaScript function
I have a PHP script where a user can upload an image. This image
send some image data in base64 and collect in hanlder and get message object
1.Here i am trying to send my jpg image file as attachment to mail
I created a PNG image using PHP GD Library, added some text based on
I'm trying to use json to send text and blob image information from MySQL
I need to send out an email with multiple image attachments from PHP. I
I am attempting to send Base64 image data via ajax to Server. Sometimes all

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.