when to use url and when path
Is there a rule of thumb in which cases I should use an URl and in which a开发者_运维知识库 path?
Example:
C:\some-path\to-my\local-dev-environment\xampp\whatever
vs.
http://localhost/whatever
EDIT: What I want to acchieve is a "safe" list in which cases I should use/avoid using and URl and in which I should use/avoid a path. Additional: What impact on performance does it have?
It's really a question of access.
If the entity in question has legitimate access to your file system then go with the path.
If the entity does not have access to your file system, but you would still like to grant him some sort of access via a web technology, then go with a URL.
EDIT
Performance:
The Path is always be more performant since it is generally used on the same computer (server) or at least on the same intranet. Aside from also bypassing the Web protocols used by URLs.
The URL is always considered less performant since the request is being routed through an HTTP,FTP, or other protocol which then converts the request to a Path request and then serves the file to the end destination. So what you should realize is that all URL (file) requests eventually get converted to a Path. In this sense, URL is just another way to access the Path of another computer via a web technology.
"Safe" list (not comprehensive):
Use URLs for
- Wiki, Microsoft Sharepoint, other Portal type access
- Integrating with a third party app that is external to your environment (hosted outside your network)
- Sharing a document across your disconnected intranets
- Sharing a public document to the world
Use Path for
- Local file CRUD operation (Create, Read, Update, Delete)
- Integrating with a third party app that is internal to your environment (hosted on your network)
- Local Intranet CRUD operations
More or less here is here general rule of thumb.
If you can navigate to the file without using a URL that's probably how you should access it with your program.
Use the path when using paths server side in code.
Use the URL when composing URLs such as links, redirects, etc.
URL are generally used for accessing global resources like http, ftp links, where as path for local resources like local files etc.
精彩评论