将 Href 设置为服务器路径
如何正确将 Href 设置为服务器上的文件(例如:\myserver\test\a.txt)?当我将路径分配给 Href 时,它在前面添加了域名(http://mydomain.com/myserver/test/a.txt),这不是正确的路径。
How do I set Href to a file on a server (example: \myserver\test\a.txt) correctly? When I assign the path to Href, it adds the domain name in front (http://mydomain.com/myserver/test/a.txt) which is not the correct path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 file:/// URI 范例。例如,我可以在浏览器中访问
file:////sharename/c$/
并且它可以工作。Try using the file:/// URI paradigm. For example, I can go in my browser to
file:////sharename/c$/
and it works.您无法从客户端从服务器下载文件。您必须在服务器端执行此操作,或者确保可以通过将要在 href 中提供的文件添加到托管目录中来访问该文件。
如果您不想手动移动服务器上的文件,更好的方法之一是在服务器端编写代码,从您指定的服务器上的任何位置复制该文件,并将其放入托管目录中。文件位于托管目录中后,您可以创建一个链接并将其提供给用户下载或访问。
You can't download a file from server from your client side. You have to do this on your server side or make sure that the file which you want to give in href is accessible by adding it in your hosted directory.
One of the better way if you dont want to manually move the files on server is to write code on server side to make a copy of that file from any location on that server as specified by you and put it in hosted directory. Once the file is in hosted directory you can create a link and give it to user for download or access.