Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've got something working in Chrome after much, much, much detective work. This <em>only</em> works on Chrome. On Safari, it freezes. On Firefox, it won't let me drop the file. IE opens the dropped file instead. Even in Chrome, the drag and drop only works once, for some reason, after which you have to refresh the page. (A possible reason for this is that something is wrong with the event handlers.)</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; window.onload = function () { var div = document.getElementById('div'); div.ondragenter = div.ondragover = function (e) { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; return false; } div.ondrop = function (e) { for (var i = 0; i &lt; e.dataTransfer.files.length; i++) { // e.dataTransfer is a DataTransfer object (https://developer.mozilla.org/En/DragDrop/DataTransfer), e.dataTransfer.files is a FileList object (https://developer.mozilla.org/en/DOM/FileList) var file = e.dataTransfer.files[i]; // file is a File object (https://developer.mozilla.org/en/DOM/File) var xhr = new XMLHttpRequest; xhr.open('post', 'handler.php', true); xhr.onreadystatechange = function () { if (this.readyState != 4) return; document.body.innerHTML += '&lt;pre&gt;' + this.responseText + '&lt;/pre&gt;'; } xhr.setRequestHeader('Content-Type', 'multipart/form-data'); xhr.setRequestHeader('X-File-Name', file.fileName); xhr.setRequestHeader('X-File-Size', file.fileSize); xhr.send(file); // For some reason sending the actual File object in Chrome works? } e.preventDefault(); return false; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="div" style="width: 100%; height: 200px; border: 1px solid blue"&gt;Drop here&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>handler.php:</p> <pre><code> // This is not a true file upload. Instead, it sends the raw data directly. echo htmlentities(file_get_contents('php://input')); </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.
    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