获得从本地文件夹中的所有图像 [英] Get all images from local folder

查看:131
本文介绍了获得从本地文件夹中的所有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方式来获得从本地文件夹中的所有图片为presentation,也将在本地运行。将没有尝试对一个服务器从本地文件夹所拍摄的图像,因为这是不可能的/的情况

I need a way to get all the images from a local folder for a presentation that will also run locally. There will be no attempt for a server to take the images from a local folder since that is not possible/the case.

我需要使用的.js,因为我不能用的.php(这将是更容易),因为它运行在本地计算机上。

I need to use .js since I can't use .php (which would be easier) since it runs on a local PC.

说我需要从采取的所有图片学习/

Say I need to take all the images from learn/

我已经试过,可以发现各种解决方案<一href="http://stackoverflow.com/questions/6994212/is-there-a-way-to-return-a-list-of-all-the-image-file-names-from-a-folder-using">here, <一href="http://stackoverflow.com/questions/18480550/how-to-load-all-the-images-from-one-of-my-folder-into-my-web-page-using-jquery">here和 rel="nofollow">但没有奏效。

I have tried various solutions that can be found here, here and here but none worked.

推荐答案

我觉得你最好的选择是使用新的文件API中的JavaScript。是有很多功能从文件系统中读取文件。<​​/ P>

I think your best option is to use the new File API in Javascript. Is has a lot of functions to read files from the file system.

<input type="file" id="fileinput" multiple />
<script type="text/javascript">
  function readMultipleFiles(evt) {
    //Retrieve all the files from the FileList object
    var files = evt.target.files; 

    if (files) {
        for (var i=0, f; f=files[i]; i++) {
              var r = new FileReader();
            r.onload = (function(f) {
                return function(e) {
                    var contents = e.target.result;
                    alert( "Got the file.n" 
                          +"name: " + f.name + "n"
                          +"type: " + f.type + "n"
                          +"size: " + f.size + " bytesn"
                          + "starts with: " + contents.substr(1, contents.indexOf("n"))
                    ); 
                };
            })(f);

            r.readAsText(f);
        }   
    } else {
          alert("Failed to load files"); 
    }
  }

  document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
</script>

从<一个

(code href="http://www.htmlgoodies.com/beyond/javascript/read-text-files-using-the-javascript-filereader.html#fbid=tnER2YT8t5M"相对=nofollow>这里

您可以找到一个很好的解释和乐于助人code 这里

You can find a good explanation and helpful code here.

这篇关于获得从本地文件夹中的所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆