您如何将驱动器文件路径转换为url路径? [英] How do u convert a drive file path to url path?

查看:69
本文介绍了您如何将驱动器文件路径转换为url路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换类似
的东西 c:\\test\\file1.txt
网址
\\localhost\\c:\\test\\file1.txt

I need to convert something like
c:\\test\\file1.txt
to url
\\localhost\\c:\\test\\file1.txt

推荐答案

从我对网络托管的了解来看,这根本不是它的工作方式.本地主机实际上是指向系统上的特定文件夹,具体取决于您使用的服务器和服务器设置.您只能访问该文件夹中的文件.

我可能是错的,但是由于没有人回答,这就是我的理解,所以我认为我会把它扔出去.

您可以使用include_path使用PHP进行操作,以便能够访问外部文件.借助Apache,您可以进行别名处理(请参见将URL映射到文件系统位置 [ ^ ]),我认为您可以对其他服务器执行相同的操作.但是,您必须告诉服务器这些类型的东西.否则,任何人都可以键入您想要的内容并造成各种破坏.
From what I understand of web hosting, that is not the way it works at all. Depending on what server you''re using and what the server settings are, localhost is actually pointing to a specific folder on your system. You can only access files located within that folder.

I could be wrong, but since no one else had replied and that is how I understand it, I thought I would throw that out there.

You can do things with PHP using include_path to be able to access files outside. And with Apache, you can do things like Aliasing (see Mapping URLs to Filesystem Locations[^]) and I assume you can do the same with other servers. But, you have to tell the server those types of things. Otherwise, any person could type what you wanted to and create all kinds of havoc.


如果这是针对ASP.Net的,反之亦然,您可以使用Server.MapPath,但是这种方式,我认为您可以强行使用它:)

If this has been for ASP.Net and vice-versa you could have used Server.MapPath but this way, I think you can brute-force it :)

string serverName = "localhost";
string filePath = "c:\\test\\file1.txt";
string result = string.Format("\\{0}\\{1}",
    serverName, filePath.Replace(":", "


")));
"));



我认为,在使用url的情况下,您必须将



I think in case of url you have to replace : with


这篇关于您如何将驱动器文件路径转换为url路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆