简体   繁体   English

html5文件api,将用户选择的目录存储在sessionStorage中?

[英]html5 file api, storing user selected directory in sessionStorage?

I'd like to make an application where a user can select a directory on their own computer, and I can refer to the images in that directory across page refreshes/etc. 我想创建一个用户可以在其自己的计算机上选择目录的应用程序,并且可以在页面刷新/等中引用该目录中的图像。 For example, the user selects a directory, or just multiple image files, and then every time the page is refreshed, display a random image from the selected directory. 例如,用户选择一个目录,或仅选择多个图像文件,然后每次刷新页面时,从所选目录中显示随机图像。 I don't want the images to get uploaded to my server, rather allow users to customize the experience by selecting which images get displayed on a session-by-session basis. 我不想将图像上传到我的服务器,而是允许用户通过选择逐个会话显示哪些图像来定制体验。 I know it sounds like a very obscure scenario, but there is at least one circle of people I know of who will really appreciate this functionality. 我知道这听起来像是一个非常晦涩的场景,但是我认识的至少有一个圈子的人会真正欣赏此功能。

Is there some way to achieve this with the HTML5 file api? 是否可以通过HTML5文件api实现此目的?

I'm currently using: 我目前正在使用:

$imagesDir = 'random/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];

to serve a random image from a directory on my server at each page refresh. 在每次刷新页面时从服务器上的目录中提供随机图像。 I'd like the user to be able to replace this directory with a directory they select on their own computer. 我希望用户能够用他们在自己的计算机上选择的目录替换此目录。

Grabbing them from an average (user selected) directory on the user's computer is not possible (see this answer for more in-depth info). 无法从用户计算机上的普通(用户选定)目录中获取它们(有关更多详细信息,请参阅此答案 )。
Basically you can not serialize/store the user-selected directory, neither do you have a directory-indexing method (for local files), so the user would still have to select each and every file (they want to share to your web-app) separately. 基本上,您不能序列化/存储用户选择的目录,也没有目录索引方法(用于本地文件),因此用户仍然必须选择每个文件(它们要共享到您的Web应用程序) )分别。 Likewise, you can not store references to those files (beyond sessions). 同样,您不能存储对这些文件的引用(超出会话)。

You could however have them (the users) select files (images) from their computer and 'upload' them into the browser's local storage area (that is technically still on the user's computer). 但是,您可以让他们(用户)从他们的计算机中选择文件(图像),然后将它们“上传”到浏览器的本地存储区域(从技术上讲,仍在用户计算机上)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM