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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:49:42+00:00 2026-05-17T19:49:42+00:00

Admittedly, there are similar questions lying around on Stack Overflow, but it seems none

  • 0

Admittedly, there are similar questions lying around on Stack Overflow, but it seems none quite meet my requirements.

Here is what I’m looking to do:

  • Upload an entire form of data, one piece of which is a single file
  • Work with Codeigniter’s file upload library

Up until here, all is well. The data gets in my database as I need it. But I’d also like to submit my form via an AJAX post:

  • Using the native HTML5 File API, not flash or an iframe solution
  • Preferably interfacing with the low-level .ajax() jQuery method

I think I could imagine how to do this by auto-uploading the file when the field’s value changes using pure javascript, but I’d rather do it all in one fell swoop on for submit in jQuery. I’m thinking it’s not possible to do via query strings as I need to pass the entire file object, but I’m a little lost on what to do at this point.

Can this be achieved?

  • 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-17T19:49:42+00:00Added an answer on May 17, 2026 at 7:49 pm

    It’s not too hard. Firstly, take a look at FileReader Interface.

    So, when the form is submitted, catch the submission process and

    var file = document.getElementById('fileBox').files[0]; //Files[0] = 1st file
    var reader = new FileReader();
    reader.readAsText(file, 'UTF-8');
    reader.onload = shipOff;
    //reader.onloadstart = ...
    //reader.onprogress = ... <-- Allows you to update a progress bar.
    //reader.onabort = ...
    //reader.onerror = ...
    //reader.onloadend = ...
    
    
    function shipOff(event) {
        var result = event.target.result;
        var fileName = document.getElementById('fileBox').files[0].name; //Should be 'picture.jpg'
        $.post('/myscript.php', { data: result, name: fileName }, continueSubmission);
    }
    

    Then, on the server side (i.e. myscript.php):

    $data = $_POST['data'];
    $fileName = $_POST['name'];
    $serverFile = time().$fileName;
    $fp = fopen('/uploads/'.$serverFile,'w'); //Prepends timestamp to prevent overwriting
    fwrite($fp, $data);
    fclose($fp);
    $returnData = array( "serverFile" => $serverFile );
    echo json_encode($returnData);
    

    Or something like it. I may be mistaken (and if I am, please, correct me), but this should store the file as something like 1287916771myPicture.jpg in /uploads/ on your server, and respond with a JSON variable (to a continueSubmission() function) containing the fileName on the server.

    Check out fwrite() and jQuery.post().

    On the above page it details how to use readAsBinaryString(), readAsDataUrl(), and readAsArrayBuffer() for your other needs (e.g. images, videos, etc).

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

Sidebar

Related Questions

No related questions found

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.