문제

I am a little confused with relative path. A simple example “C:\program files\files”. I would say the relative path for the current directory is “.\program files\files”. But I get error that it can’t find. What am I missing?

도움이 되었습니까?

해결책

Relative Paths

A relative path assumes that the file is on the current server. Using relative paths allows you to construct your site offline and fully test it before uploading it.

For example:

php/webct/itr/index.php

.

Absolute Paths

An absolute path refers to a file on the Internet using its full URL. Absolute paths tell the browser precisely where to go.

For example:

http://www.xuz.com/disted/php/webct/itr/index.php

Absolute paths are easier to use and understand. However, it is not good practice on your own website. For one thing, using relative paths allows you to construct your site offline and fully test it before uploading it. If you were to use absolute paths you would have to change your code before uploading it in order to get it to work. This would also be the case if you ever had to move your site or if you changed domain names.

다른 팁

A relative path is relative to some other path, usually your current working directory. For example, if you type the MS-DOS command cd \program files on your C: drive, a relative path from there would be files\ or Microsoft\Office. Note the lack of a drive letter or a preceding backslash. A UNIX-like environment would be similar; for example, a relative path to /usr/share/man from /usr would be share/man.

Note that a relative path may not be from your current working/default directory, but rather from some other directory specified as a "default" by a program.

It depends from where you are requesting the resource. Let's suppose that you have a script requesting C:\Program Files\Files\targetimage.jpg. Let's suppose that your script is in C:\Program Files directory. Then the path, relative to your script position, would be .\Files\targetimage.jpg.

I hope this was clear enough.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top