0

I want to write a client side script with a form where you can upload a large file (>2GB) to the server. The server would not be able to process such a big file with a regular html upload so the file has to be splitted in to multiple fileparts. Therefore my html form is:

<form enctype="multipart/form-data" method="post" id="fileinfo" name="fileinfo">
          <label>Your email address:</label>
          <input type="email" autocomplete="on" autofocus name="userid" placeholder="email" required size="32" maxlength="64" /><br />
          <label>Custom file label:</label>
          <input type="text" name="filelabel" size="12" maxlength="32" /><br />
          <label>File to stash:</label>
          <input type="file" name="file" required />
</form>        
<a href="javascript:sendForm()">Stash the file!</a>

The jQuery is:

function sendForm() {
     var fd = new FormData(document.getElementById("fileinfo"));
     fd.append("CustomField", "This is some extra data");
     $.ajax({
        url: "stash.php",
        type: "POST",
        data: fd,
        processData: false,  // tell jQuery not to process the data
        contentType: false,   // tell jQuery not to set contentType
        success: function(response){
             console.log("Response was "  + response);
        },
        failure: function(result){
            console.log("FAILED");
            console.log(result);
        }
    });

};

My php script is really short at the moment because I just wanted to test if it receives the form data:

if (isset($_POST['filelabel']) ) { var_dump('sent'); var_dump($_POST); }

But how to make "blobs" and set the size of the file parts? And how to proceed afterwards? Any tips, links or code snippets would be useful!

user2718671
  • 2,866
  • 9
  • 49
  • 86

1 Answers1

1

I would recommend using jquery fileupload plugin.... its the easyiest way to get what you want https://blueimp.github.io/jQuery-File-Upload

Also take a look at this attached plugin: https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads

Fernando Rybka
  • 238
  • 1
  • 4
  • 14
  • 2
    OMG! The documentation and the tutorials to the jQuery-File-Upload are really confusing. There is an example that works but it's quite hard to customize the uploader. Many people seems to have problems with it: http://stackoverflow.com/questions/17934689/can-someone-explain-how-to-implement-the-jquery-file-upload-plugin and tutorials got a lack of code: http://www.htmlgoodies.com/html5/other/using-html5-and-the-blueimp-jquery-file-upload-plugin-to-upload-large-files.html#fbid=OpMLzRHv0fQ The author of the stack overflow question recommended Uploadify but it's not a free tool... :( – user2718671 Feb 20 '14 at 10:07
  • Yes, its quite hard to configure, I used it in a project once and had a little trouble. Though I still think its the easiest way to do so (remember that a solution by your own you will have to test an certify its work in several browsers and connections, and etc, etc, not an easy job either) Wish you good luck! – Fernando Rybka Feb 20 '14 at 11:43