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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:25:57+00:00 2026-06-13T05:25:57+00:00

client side code <head> <script> var reader = new FileReader(); var objVal; var image

  • 0

client side code

<head>
<script>
var reader = new FileReader(); 
var objVal;
var image = new Image();
reader.onload = function(e) {
    document.getElementById('propertyImg').setAttribute('src', e.target.result);
};

function readURL(input){    
    if(input.files && input.files[0]){
        reader.readAsDataURL(input.files[0]);
    }
    else {
        document.images[0].src = input.value || "No file selected";
    }
}

function sendPost(){
            var url = 'http://myurl.com';
            var name = document.getElementById('fileInput').files[0].name;
    var data = document.getElementById('propertyImg').getAttribute('src');
    var f = document.createElement("form"); 
    var imgName = document.createElement("input"); 
    var imgData = document.createElement("input"); 
    var f_attr = { 'method' : 'post' , 'action' : url};
    var imgName_attr = {"type" : "hidden", "name" : "img_name", "value" : name};
    var imgData_attr = {"type" : "hidden", "name" : "data", "value" : data};
    setAttributes(f, f_attr);
    setAttributes(imgName, imgName_attr);
    setAttributes(imgData, imgData_attr);
    f.appendChild(imgName);
    f.appendChild(imgData);
    document.body.appendChild(f); 
    f.submit(); 
}

function setAttributes(el, attrs) {
    for(var key in attrs) {
        el.setAttribute(key, attrs[key]);
    }
}
</script>
<body>
   <img id="propertyImg" src="./img/sprite.png"></img>  
   <input type='file' id='fileInput'class='width70_prop' onchange="readURL(this);"></input>
   <button onclick="sendPost()">sendPost</button>
</body>

serverside code

<html>
    <head>
    <?
          $FileName = $_POST['img_name']; 
          $data = $_POST['data']; 
          list($header, $content) = split('[,]', $data); 
          file_put_contents($FileName, base64_decode($content));
          print "Data Written"; 
     ?>
    <script>
    function showImg(){
    var imgSrc =  "<?=$data?>";
    var imgDiv = document.getElementById('imgDiv');
    imgDiv.src = imgSrc;
    }
    </script>
    </head>
    <body>
    <img id='imgDiv'></img>
    <button onclick="showImg()">show</button>
    </body>
</html>

the blob sent to server had infomation about header and its content.
when I split header then save decoded its content, it worked….
I changed above code which now works. thx guys

  • 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-13T05:25:59+00:00Added an answer on June 13, 2026 at 5:25 am

    First, there isn’t anything in $_POST["data"] because the index (data) is named by the key in the JSON key : value pair, not the JavaScript var.

    Secondly, you should change this:

    $Handle = fopen($FileName, 'w');
    fwrite($Handle, $data); 
    print "Data Written"; 
    fclose($Handle);
    

    to this:

    file_put_contents($FileName, base64_decode($data));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Client side javascript code creates some elements (about 50-100) in a cycle: for (var
I'm writing a piece of client-side javascript code that takes a function and finds
Heres my client-side code <!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>Alerter</title> </head> <body>
I need to build some client side code which follows this use case: An
I need to be able to diagnose client-side code issues using IE9 (F12) developer
So I understand that JSPs are a mixture of a client-side code (DHTML, JS,
Here's my client-side jQuery code: $.ajaxSetup ({ contentType: application/json, datatype: 'json' }); $.ajax({ type:
Can I test my client side GWT code without GWTTestCase? I've heard somewhere (I
I have a server-side code using .NET Remoting to establish the connection with client.
How can I create an environment in client-side javascript where any code related to

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.