Absolute path and relative path of the file

Source: Internet
Author: User

When using DW to write HTML, you can directly select the path to the specific file, now use Webstorm, can only choose to the same directory with the HTML file. This is the difference between the absolute path and the relative path of the file.

1. Absolute path

First of all, on the local computer, the absolute path of the file is, of course, the path that the file really exists on the hard disk.

For example, this path:d:/wamp/www/img/icon.jpg tells us that the Icon.jpg file is in the IMG subdirectory of the Wamp directory in the D drive. We do not need to know any other information to determine the location of the file based on the absolute path.

There are also hyperlink file locations, which also belong to absolute paths, such as http://www.img.net/img/icon.jpg .

Note: sometimes compiled pages, browsing on their own computer all normal, but uploaded to the Web server browsing is likely not to display pictures. Because static HTML pages need to be uploaded to the site, and in the application of the site, usually we use "/" to represent the root directory,/img/icon.jpg represents the Photo.jpg file in the root directory of this site in the IMG directory . But be aware that the root directory you are referring to is not the root of your site, but the root of the Web server where your site resides. Since uploading to a Web server, it is possible that the entire Web site does not have a D drive on the Web server, possibly an F or H drive. Even if placed in the Web server's D disk, the Web server's e disk will not necessarily exist "d:/wamp/www/img" This directory, so when browsing the Web page will not display the picture. This is also the risk of applying an absolute path.

2. Relative path

The relative path, as the name implies, is relative to the target position.

Suppose you want to introduce a file page name is test.htm, it exists in the folder called www ( absolute path d:/wamp/www/test.htm), then the reference exists in the WWW folder " Icon.jpg "file ( absolute path d:/wamp/www/icon.jpg), relative path under the same directory icon.jpg; if the file" Icon.jpg "exists in the IMG folder ( absolute path d:/wamp/www/img/icon.jpg), then the relative path img/ Icon.jpg.

Relative paths can avoid different problems with the above root directory. As long as the relative location of the Web page files and the reference files is kept consistent with the relative location of the files on the Web server, their relative paths will also be consistent. For example, the "test.htm" file refers to the "icon.jpg" image, because "icon.jpg" picture is in the same directory as the "test.htm", so long as the two files are still in the same directory, The image can be displayed correctly in the browser, regardless of where it was uploaded to the Web server.

Note:The relative path uses the "/" character as the separator character for the directory, and the absolute path can use the "\" or "/" wordCharacter as the delimiter for the directory. Since the "IMG" Directory is a subdirectory under the "www" directory, there is no need to add the "/" character before "IMG". Often used in relative paths ". /"to represent the previous level of the directory. If there are multiple top-level catalogs, you can use more than one ". /”。 Assume that the "test.htm" file is in the same directory as "d:/wamp/www/test.htm", and the" icon.jpg "image is located in the directory"d:/wamp/www", then the" icon.jpg "image, in relation to the" test.htm "file, is in the parent directory of the directory in which it is located, then the statement referring to the picture should be:Assume that the "test.htm" file is in the same directory as "d:/wamp/www/test.htm", and the" icon.jpg "image is located in the directory"d:/wamp/www", then the" icon.jpg "image, in relation to the" test.htm "file, is a subdirectory in the parent directory of its Directory-" IMG ", the statement referring to the picture should be: 3. Virtual path When files are uploaded to a remote server, the files reside in a folder in the server's local directory tree. For example, on a server running Microsoftiis, the path to the home page might resemble the following:c:\Inetpub\wwwroot\accounts\users\jsmith\index2.htmThis path is often referred to as the file'sPhysical Path。 However, the URL used to open the file does not use a physical path. It usesServer nameor domain name, followed by the virtual path (in this case the virtual directory: Virtual directory, is the HTTP access, the user when browsing the site or FPT display directory structure. For example you set the E:\Website to access the directory, then E:\Website is the root directory of the virtual directory; E:\Website\Image, it becomes \image. )。 So with the example above, the virtual path can be written Tidy up. "./" represents the current directory equals ". /" represents the top level directory "/" current root directory, is relative directory; "~/" Web application root directory. ASP. NET enables the Web application root operator (~), which can be used when specifying a path in a server control. asp. NET resolves the ~ operator to the root directory of the current application. You can use the ~ operators and folders together to specify the path based on the current root directory.<asp:image runat= "Server" id= "Image1" imageurl= "~/images/sampleimage.jpg"/>In this example, the image file is read directly from the Images folder in the Web application root directory, regardless of where the page is located on the site. 

Absolute path and relative path of the file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.