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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:45:05+00:00 2026-05-24T06:45:05+00:00

if(up.xhr.sendAsBinary != null) { //firefox up.xhr.open(‘POST’, ‘/html5_upload.php?up=true’, true); var boundary = ‘xxxxxxxxx’; var body

  • 0
if(up.xhr.sendAsBinary != null) { //firefox

    up.xhr.open('POST', '/html5_upload.php?up=true', true);

    var boundary = 'xxxxxxxxx';

    var body = '--' + boundary + "\r\n";  
    body += "Content-Disposition: form-data; name='upload'; filename='" + up.processing.name + "'\r\n";  
    body += "Content-Type: application/octet-stream\r\n\r\n";  
    body += binary + "\r\n";  
    body += '--' + boundary + '--';  

    up.xhr.setRequestHeader('content-type', 'multipart/form-data; boundary=' + boundary);
    up.xhr.sendAsBinary(body);          

} else { //for browsers that don't support sendAsBinary yet

    up.xhr.open('POST', '/html5_upload.php?up=true&base64=true', true);

    up.xhr.setRequestHeader('UP-FILENAME', up.processing.name);
    up.xhr.setRequestHeader('UP-SIZE', up.processing.size);
    up.xhr.setRequestHeader('UP-TYPE', up.processing.type);

    up.xhr.send(window.btoa(binary)); 
}

Hi I’ve copied this code from a website and I’m trying to understand hows it works. I’m wondering what’s the difference between two methods of sending the file over to php. Is there any benfits in using one instead of the other?

  • 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-24T06:45:05+00:00Added an answer on May 24, 2026 at 6:45 am

    The btoa function is described in the HTML5 spec. It appears not all browser have this method implemented.

    Here is the source article for your example.

    The 1st example (sendAsBinary) creates the form post data as defined in RFC 2388.

    The 2nd example (btoa) uses a custom payload (base64 encoded value of file contents).

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

Sidebar

Related Questions

I have such part of code: var xhr = new XMLHttpRequest(); xhr.open(POST, http://someurl.com, true);
I have a script that posts data to a php script: xhr.open(POST,processData.php); And i
var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://static.reddit.com/reddit.com.header.png', true); xhr.responseType = 'arraybuffer'; xhr.onload = function(e)
I've got the following synchronous request... var xhr = new XMLHttpRequest(); xhr.open(GET,uri,false); xhr.send(null); I've
I have problem with xhr open() method. My code follows : var xmlhttp=false; if(!xmlhttp)
i have the following javascript in my webpage: var xhr = new XMLHttpRequest(); xhr.open('GET',
I saw this code sample without any explanation: var xhr = new XMLHttpRequest(); xhr.open('GET',
function connectTo(url) { var xhr = new XMLHttpRequest(); xhr.open(GET, url, false); xhr.onreadystatechange = function
function fetchXmlDoc(uri) { var xhr = new XMLHttpRequest(); var async = false; xhr.open(GET, uri,
Suppose we have the xhr 'POST' request that returns 'redirect' status code. In that

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.