Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not too hard. Firstly, take a look at <a href="http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface" rel="noreferrer">FileReader Interface</a>.</p> <p>So, when the form is submitted, catch the submission process and</p> <pre><code>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 = ... &lt;-- 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); } </code></pre> <p>Then, on the server side (i.e. myscript.php):</p> <pre><code>$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" =&gt; $serverFile ); echo json_encode($returnData); </code></pre> <p>Or something like it. I may be mistaken (and if I am, please, correct me), but this should store the file as something like <code>1287916771myPicture.jpg</code> in <code>/uploads/</code> on your server, and respond with a JSON variable (to a <code>continueSubmission()</code> function) containing the fileName on the server.</p> <p>Check out <a href="http://us2.php.net/manual/en/function.fwrite.php" rel="noreferrer"><code>fwrite()</code></a> and <a href="http://docs.jquery.com/Post" rel="noreferrer"><code>jQuery.post()</code></a>.</p> <p>On the above page it details how to use <a href="http://dev.w3.org/2006/webapi/FileAPI/#readAsBinaryString" rel="noreferrer"><code>readAsBinaryString()</code></a>, <a href="http://dev.w3.org/2006/webapi/FileAPI/#readAsDataURL" rel="noreferrer"><code>readAsDataUrl()</code></a>, and <a href="http://dev.w3.org/2006/webapi/FileAPI/#readAsArrayBuffer" rel="noreferrer"><code>readAsArrayBuffer()</code></a> for your other needs (e.g. images, videos, etc).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload