在页面中显示桌面上的图像

时间:2014-08-25 13:51:11

标签: php upload

我动态地生成一个php页面,其中包含我在之前的表单中添加的信息。 我想在我的桌面的桌面中添加(不上传)图片,然后将其显示在我生成的页面中。我不是要求你这样做,但我只是想知道它是否可能。

谢谢

1 个答案:

答案 0 :(得分:1)

(但不是永久性的)

这就是答案。更具体您需要做的事情:

让用户通过表单input="file"选择文件,通过JavaScript读取文件并在网站上输出blob。

这是一个很好的教程:http://www.html5rocks.com/en/tutorials/file/dndfiles/

他们使用的主要代码:

function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);