Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload .xls file on PHP server using the HTML5 File API
    primarykey
    data
    text
    <p>I all,</p> <p>I'm trying to upload an xls file using the HTML5 API.</p> <p>I already have a script which is working great for images.</p> <p>It's also working with an xls file except the fact that I can't open the file using excel once it has been uploaded... If I compare the size, the orignal file is 251 904 octets while the upload one is 251 911 octets. I don't know if that matter.</p> <p>Here is what i've done :</p> <p>Javascript:</p> <pre><code>reader = new FileReader(); reader.onloadend = function(evt) { that.file = evt.target.result; }; reader.readAsDataURL(file); // I've also try with readAsText but it's worse </code></pre> <p>the file is send using Sproutcore Framework:</p> <pre><code>SC.Request.postUrl(url).json() .notify(this, 'fileUploadDidComplete', fileName) .send({ fileName: fileName, file: file }); </code></pre> <p>PHP:</p> <pre><code>$httpContent = fopen('php://input', 'r'); $json = stream_get_contents($httpContent); fclose($httpContent); $data = json_decode($json, true); $file = base64_decode($data['file']); $fileName = substr(md5(time().rand()), 0, 10).$data['fileName']; $filePath = GX_PATH."/files/tmp/".$fileName; $handle = fopen($filePath, "w"); fwrite ($handle, $file); fclose($handle); </code></pre> <p>I hope somebody will help me to find what is wrong.</p> <p>Thanks in advance.</p> <p><strong>EDIT:</strong></p> <p>I find another way which work on more browsers. I've discover FormData !</p> <pre><code>formData = new FormData(); formData.append("file", file); SC.Request.postUrl(url).notify(this, 'formDataDidPost').send(formData); </code></pre> <p>This way, the PHP code is more simple :</p> <pre><code>$_FILES['file']; </code></pre>
    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. 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