简体   繁体   English

如何使用Javascript从文件夹中获取文件数组

[英]How to get array of files from a folder using Javascript

Scenario: I am creating a personal home page that i plan for using in safari/chrome/Firefox and I have a folder with images. 场景:我正在创建一个个人主页,计划在safari / chrome / Firefox中使用它,并且我有一个包含图像的文件夹。 I want to display a random image as the background of the page. 我想显示一个随机图像作为页面的背景。

My solution to this was to create an array with all the images as separate links as the objects of the array. 我对此的解决方案是创建一个数组,其中所有图像作为该数组的对象作为单独的链接。 My JS works with a pre-made array of links but I have no clue on how to create an array from a directory. 我的JS使用预制的链接数组,但是我不知道如何从目录创建数组。

I don't mind using jquery if required but i cant have server side php (or anything else) since i am linking the local html file to the new tab page.\\ 我不介意使用jquery(如果需要),但由于我将本地html文件链接到新标签页,因此我无法安装服务器端php(或其他任何工具)。\\

The html file is in the directory / and the images in /img . html文件位于目录/中,图像位于/ img中。

This can't be done. 无法做到这一点。 You're going to need something on the server side to read the directory that is on your server . 你将需要在服务器端的东西读这是你的服务器上的目录。 Javascript (including jQuery) running on the user's browser doesn't have access to list directories on your server. 在用户浏览器上运行的Javascript(包括jQuery)无权访问服务器上的列表目录。

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

相关问题 如何使用 javascript 将从表单提交的文件获取到本地文件夹 - How to get files submitted from a form into a local folder using javascript 如何使用javascript获取文件夹中的文件列表 - how get list of files in a folder using javascript JavaScript从文件夹中获取所有图像文件,并将其名称附加到数组 - JavaScript get all image files from folder and append their names to array 如何遍历文件夹中的文本文件,使用JavaScript从每个文件中读取内容以形成字符串数组 - How to loop through text files in a folder, read the contents from the each file to form a string array using javascript javascript如何从服务器获取文件夹中文件的URL? - javascript how to get urls to files in folder from server? 如何使用javascript从HTML获取数组? - How to get an array from html using javascript? 如何使用JavaScript从Sharepoint列表中的文件夹中获取项目? - How get items from folder in Sharepoint list using JavaScript? 如何使用 JavaScript 列出文件夹中的本地文件? - How to list local files in a folder using JavaScript? 如何从图像文件夹文件中制作 URL 路径数组? 使用 Javascript - How do you make into array of URL paths out of image folder files? Using Javascript 如何使用 JavaScript 从多维数组中获取动态数组元素? - How to get dynamic array elements from multidimensional array using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM