Home > Backend Development > PHP Tutorial > javascript - 请问:在输入框内粘贴图片并上传到服务器,怎么用PHP+JS实现?

javascript - 请问:在输入框内粘贴图片并上传到服务器,怎么用PHP+JS实现?

WBOY
Release: 2016-06-06 20:27:39
Original
1176 people have browsed it

在输入框内粘贴图片并上传到服务器,请问怎么用PHP实现?(并不是上传本地文件的那种,是从剪切板来的)

回复内容:

在输入框内粘贴图片并上传到服务器,请问怎么用PHP实现?(并不是上传本地文件的那种,是从剪切板来的)

这个需要HTML5中的File API功能吧? IE8多半是支持不了:

<code>document.onpaste = function(event){
  var items = event.clipboardData.items;
  for (index in items) {
    var item = items[index];
    if (item.kind === 'file') {
      var blob = item.getAsFile();
      var reader = new FileReader();
      reader.onload = function(evt){
         console.log(evt.target.result)
      };
      reader.readAsDataURL(blob);
  }
}
</code>
Copy after login

不过!!!!不要误以为可以直接复制一个图片文件然后粘贴,一个图片文件和你按PrntScr键或者在windows画图中复制的图片内容是两码事!!!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template