简体   繁体   中英

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?

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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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