代码之家  ›  专栏  ›  技术社区  ›  Sebastien Lachance Shail

让html链接打开文件夹的方法有哪些

  •  84
  • Sebastien Lachance Shail  · 技术社区  · 17 年前

    我需要让应用程序的用户通过单击网页内的链接打开文件夹。文件夹的路径位于网络上,可以从任何地方访问。我可能肯定没有简单的方法可以做到这一点,但也许我错了?

    6 回复  |  直到 17 年前
        1
  •  113
  •   Andrew Duffy    17 年前

    file: 链接,但有一些警告:

        2
  •  8
  •   dialogik    11 年前

    网址 file://[servername]/[sharename] 应打开网络上共享文件夹的资源管理器窗口。

        3
  •  5
  •   lock    17 年前

    例如

    <a href="./downloads/folder_i_want_to_display/" >Go to downloads page</a>
    

    确保该目录中没有index.html任何索引文件

        4
  •  5
  •   Bickie    14 年前

    如果您只希望用户能够下载/查看位于网络或共享上的文件*,则可以在IIS中设置虚拟目录。在“属性”选项卡上,确保选择了“位于另一台计算机上的共享”,并且“连接方式…”是可以查看网络位置的帐户。

    从您的网页链接到虚拟目录(例如。 http://yoursite/yourvirtualdir/

    *您可以允许对虚拟目录的写入权限,以允许用户添加文件,但不尝试,并假定网络权限将覆盖此设置。

        5
  •  5
  •   Lucas Taulealea    7 年前

    我在笔记本电脑上使用xampp在windows上运行纯本地网站应用程序。(我知道这是一个非常特殊的环境)。在本例中,我使用指向php文件的html链接并运行:

    shell_exec('cd C:\path\to\file');
    shell_exec('start .');
    

        6
  •  4
  •   xinthose    5 年前

    我决定做的是在每个人的计算机上安装一个本地web服务来监听端口 9999 例如,并在被告知时在本地打开一个目录。我的示例node.js express应用程序:

    import { createServer, Server } from "http";
    
    // server
    import express from "express";
    import cors from "cors";
    import bodyParser from "body-parser";
    
    // other
    import util from 'util';
    const exec = util.promisify(require('child_process').exec);
    
    export class EdsHelper {
        debug: boolean = true;
        port: number = 9999
        app: express.Application;
        server: Server;
    
        constructor() {
            // create app
            this.app = express();
            this.app.use(cors());
            this.app.use(bodyParser.json());
            this.app.use(bodyParser.urlencoded({
                extended: true
            }));
    
            // create server
            this.server = createServer(this.app);
    
            // setup server
            this.setup_routes();
            this.listen();
            console.info("server initialized");
        }
    
        private setup_routes(): void {
            this.app.post("/open_dir", async (req: any, res: any) => {
                try {
                    if (this.debug) {
                        console.debug("open_dir");
                    }
    
                    // get path
                    // C:\Users\ADunsmoor\Documents
                    const path: string = req.body.path;
    
                    // execute command
                    const { stdout, stderr } = await exec(`start "" "${path}"`, {
                        // detached: true,
                        // stdio: "ignore",
                        //windowsHide: true,    // causes directory not to open sometimes?
                    });
    
                    if (stderr) {
                        throw stderr;
                    } else {
                        // return OK
                        res.status(200).send({});
                    }
                } catch (error) {
                    console.error("open_dir >> error = " + error);
                    res.status(500).send(error);
                }
            });
        }
    
        private listen(): void {
            this.server.listen(this.port, () => {
                console.info("Running server on port " + this.port.toString());
            });
        }
    
        public getApp(): express.Application {
            return this.app;
        }
    
    }
    


    http://localhost:9999/open_dir { "path": "C:\Users\ADunsmoor\Documents" } .

        8
  •  2
  •   Wyrmwood    13 年前

    您还可以复制链接地址并将其粘贴到新窗口中,以绕过安全保护。这适用于chrome和firefox,但您可能需要在firefox中添加斜杠。

        9
  •  2
  •   Nagaraja JB    6 年前

    希望有一天它能帮助别人。我在做一个小POC时遇到了这个。

    <input type=button onClick="parent.location='file:///C:/Users/' " value='Users'>