Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>you copy (CTRL-C) an image from your desktop and paste (CTRL-V) it onto the website.</p> </blockquote> <p>No, that is <a href="http://dev.w3.org/2006/webapi/clipops/#pasting-html-and-multi-part-data" rel="noreferrer">impossible</a>. What you can paste is e.g. screenshots and images from the web, that's <a href="http://gmailblog.blogspot.fi/2011/06/pasting-images-into-messages-just-got.html" rel="noreferrer">what gmail does</a>.</p> <p>Your biggest mistake is using FileReader when you already have a file, the <code>$_FILES</code> array is filled when there is a proper HTTP upload not for ad hoc base64 POST param. To do a proper HTTP upload, you just <code>.append()</code> a file or blob object (<code>File</code>s are <code>Blob</code>s).</p> <p>This is a stand-alone PHP file that should just work, host the file, open it is a page, take a screenshot, then paste it while on the page and after a few seconds the image should appear on the page.</p> <pre><code>&lt;?php if( isset( $_FILES['file'] ) ) { $file_contents = file_get_contents( $_FILES['file']['tmp_name'] ); header("Content-Type: " . $_FILES['file']['type'] ); die($file_contents); } else { header("HTTP/1.1 400 Bad Request"); } print_r($_FILES); ?&gt; &lt;script&gt; document.onpaste = function (e) { var items = e.clipboardData.items; var files = []; for( var i = 0, len = items.length; i &lt; len; ++i ) { var item = items[i]; if( item.kind === "file" ) { submitFileForm(item.getAsFile(), "paste"); } } }; function submitFileForm(file, type) { var extension = file.type.match(/\/([a-z0-9]+)/i)[1].toLowerCase(); var formData = new FormData(); formData.append('file', file, "image_file"); formData.append('extension', extension ); formData.append("mimetype", file.type ); formData.append('submission-type', type); var xhr = new XMLHttpRequest(); xhr.responseType = "blob"; xhr.open('POST', '&lt;?php echo basename(__FILE__); ?&gt;'); xhr.onload = function () { if (xhr.status == 200) { var img = new Image(); img.src = (window.URL || window.webkitURL) .createObjectURL( xhr.response ); document.body.appendChild(img); } }; xhr.send(formData); } &lt;/script&gt; </code></pre>
    singulars
    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.
 

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