Seb*_*nce 93 html directory hyperlink
我需要让应用程序的用户通过单击网页内的链接打开文件夹.文件夹的路径位于网络上,可以从任何地方访问.我可能确定没有简单的方法可以做到这一点,但也许我错了?
And*_*ffy 100
要在Windows资源管理器中打开共享文件夹吗?您需要使用file:
链接,但有一些警告:
file://server/share/folder/
),则Internet Explorer将起作用.file://///server/share/folder
)并且用户已禁用对file:
通过HTTP提供的页面中的链接的安全限制,则Firefox将工作.值得庆幸的是,IE也接受了错误的链接表单.file:
在通过HTTP提供的页面中打开链接.小智 8
参加聚会有点晚了,但我最近必须自己解决这个问题,虽然略有不同,但它仍然可能对与我有类似情况的人有所帮助。
我在笔记本电脑上使用 xampp 在 Windows 上运行纯本地网站应用程序。(我知道一个非常具体的环境)。在本例中,我使用指向 php 文件的 html 链接并运行:
shell_exec('cd C:\path\to\file');
shell_exec('start .');
Run Code Online (Sandbox Code Playgroud)
这将打开本地 Windows 资源管理器窗口。
确保您的文件夹权限设置为允许目录列表,然后只需使用 chmod 701 将您的锚点指向该文件夹(尽管这可能有风险)例如
<a href="./downloads/folder_i_want_to_display/" >Go to downloads page</a>
Run Code Online (Sandbox Code Playgroud)
确保该目录上没有 index.html 任何索引文件
小智 5
如果安全设置设置为中等级别,则使用 file:///// 将不起作用。
如果您只是希望用户能够下载/查看位于网络或共享上的文件*,您可以在 IIS 中设置一个虚拟目录。在“属性”选项卡上,确保选择了“位于另一台计算机上的 A 共享”,并且“连接为...”是一个可以查看网络位置的帐户。
从您的网页链接到虚拟目录(例如http://yoursite/yourvirtualdir/),这将在 Web 浏览器中打开目录视图。
*您可以允许对虚拟目录的写权限以允许用户添加文件但未尝试并假设网络权限将覆盖此设置。
9999
我决定做的是在每个人的计算机上安装一个本地 Web 服务,例如侦听端口并在收到通知时在本地打开一个目录。我的示例 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;
}
}
Run Code Online (Sandbox Code Playgroud)
以本地用户而非管理员身份运行此服务非常重要,否则该目录可能永远不会打开。从您的 Web 应用程序向 localhost: 、 data:
发出 POST 请求。http://localhost:9999/open_dir
{ "path": "C:\Users\ADunsmoor\Documents" }