What is the absolute path (full path) to the file you want to write in JavaScript or CSS?

Asked 2 years ago, Updated 2 years ago, 82 views

I'm talking about CentOS (Linux), but I'm talking about HTML files in different directories and

described in JavaScript and CSS for reference from PHP files I would like to change the relative path to absolute path.

In other words, for example, JavaScript is

$("#size_simg").attr("src", "common/img/XXXXX.gif");

is written as
$("#size_simg").attr("src", "/virtual/service/example.com/http/test/common/img/XXXXXXX.gif");

I'd like to change it to the absolute path of the server, but it doesn't recognize it, so

$("#size_simg").attr("src", "http://www.example.com/test/common/img/XXXXXXX.gif");

Then they recognized it.

Personally, however, I would like to use the absolute path of the former server.

Because

http://www.example.com/test/common/img/XXXXXXX.gif

This is because if you paste directly in your browser, only XXXXXXX.gif will be displayed.

If only XXXXXXX.gif appears in the browser, the problem is not, but
I feel sick.

After all, only HTML and CSS designs that should be displayed should be hidden inside the server
I want it to appear in my browser.

A good way to make the relative path in JavaScript or CSS the absolute path of the server is
Isn't it something you don't you have any?
If anyone knows, please tell me how to do it.

[Development environment]

  • HTML
  • CSS
  • JavaScript
  • Rental Server (CentOS 5)
  • WordPress (4.1.1)
  • PHP (5.2.16)
  • Work environment (Windows 7pro)
  • For code editing (NoEditor)

javascript html css linux centos

2022-09-30 20:35

6 Answers

Judging from the question,

/virtual/service/example.com/http/test/common/img/XXXXXXX.gif

This is a way of writing that takes effect when a file is read directly into the browser on the server.
It only works on local file systems that do not include server software such as Apatch.
That is, the absolute path on the local file system.

http://www.example.com/test/common/img/XXXXXXX.gif

This is the first valid statement to be made through the server software.
This is the absolute path to view in a browser over the network.
In the example described in the question, the root directory of www.example.com is
in the server software. Local /virtual/service/example.com/http/.


if you want to display it in your browser via server software Must be able to convert to a format that starts with http/https.
In other words, the URL notation of the img file is
/virtual/service/example.com/http/test/common/img/XXXXXXX.gif
If you write , deploy to the official URL and add the protocol and domain (http://www.example.com) to your head.

http://www.example.com/virtual/service/example.com/http/test/common/img/XXXXXXX.gif

is the case.
It's not a very good way to do this, but to make it visible, you can use

on the same tier by setting up an area or symbolic link on the server side The file must be accessible.
Of course, if you hit the URL, you can view it alone.

.
Because of the characteristics of http communication, the loading is individually loaded per file, so
Static resource files can usually be viewed by tapping the URL.


If you want your browser to make it impossible to display images displayed on the page alone, etc. Referral restrictions, tokens that can only be loaded once per request from html, and
You will need to add additional actions such as embedding time limit authentication.

The former referrals are simple and light
It is easily avoided by camouflage, but the effect is reasonably high for the general public.


How do you limit the latter loading request with additional information? Accuracy increases, but loads and costs increase significantly.

Which one to adopt depends on the requirements of the content you are trying to create. It's good to judge.


2022-09-30 20:35

When HTML is displayed in the user's browser,
First, the text as HTML is loaded and
We ask the server for the files in various places, get the files, and the browser on the user's side displays (renders) the files in the appropriate position.
So if the file is written as an absolute path, it must be an absolute path that can be accessed from the network.
In other words, it has to be a file that can be retrieved (that is, can be viewed) in order to be visible to the user (the server is not configuring the display screen and transferring the entire screen).

Even if you could write with an absolute path (because of the HTTP system), the file could be acquired and displayed directly (which means showing the file system managed by the server directly), and files in the same folder could be viewed.
Rather, it goes against (the opposite you want) showing a limited part of HTTP.


2022-09-30 20:35

There is an answer to the path, so please omit it.

If you want to hide the path of the image, you have to read the image file with php and embed it in HTML.
Of course, it is necessary to determine the target image.
In the example below, I have an ID, but I can't say that PHP complements the path in the middle by passing only the file name to the parameter, but I think I can reduce the risk of opening the file directly.

As in the example, I can prepare something to link the path to the ID, but I think it will be useless if the scale gets bigger.

http://sanslanommer.com/php%E3%81%A7%E7%94%BB%E5%83%8F%E3%83%87%E3%83%BC%E3%82%BF%EF%BC%88%E3%83%90%E3%82%A4%E3%83%8A%E3%83%AA%EF%BC%89%E3%82%92%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%AB%E8%A1%A8%E7%A4%BA%E3%81%95/


2022-09-30 20:35

I didn't feel like there was an answer to the question. (But I don't know what you're asking for.)

indicated

$("#size_simg").attr("src", "http://www.example.com/test/common/img/XXXXXXX.gif");

If you mean that you do not want to include the domain in the code, then

$("#size_simg").attr("src", "/test/common/img/XXXXXXX.gif");

You can do it like this.


2022-09-30 20:35

If the server is an absolute path, write $_SERVER['DOCUMENT_ROOT'] in PHP.

If you simply mean WEB_ROOT,
like "/common/img/XXXXXX.gif" The so-called "absolute path" on the client side begins with "/.


2022-09-30 20:35

It's a little nostalgic, but there's a way to block images direct phosphorus from other sites using Referr.
This will reduce the chance of viewing images from URLs other than the servers that Web_beginner is installing.(I think it's possible for HTTP to definitely prevent it)

Write the file name .htaccess in the folder where the image is located.

SetEnvIf Refer "^http://www\.example\.com "ref_ok
order deny, allow
deny from all
allow from env=ref_ok

In the example above, unless you have the reference information for the www.example.com domain, the user will not be able to view the image directly.
Replace www.example.com with Web_beginner's URL.

However, please be aware that once you access the image while retaining the reference information, the image will be displayed.
For example:) If you go to http://www.hoge.com, you will see http://www.hoge.com/hoge.jpg.(However, if you update the screen here, the reference information will be interrupted and you won't be able to see it.)

When accessing a web page, the browser records the information reference.
This is the URL from which the link is made, and PHP can retrieve the information as follows:
If there is no link source, the code below returns null.

$refer=filter_input(INPUT_SERVER, 'HTTP_REFER');

Or

$refer=$_SERVER['HTTP_REFERER'];

I personally don't like using super global variables directly, so I always try to access them using the filter_input() function.
$_SERVER or filter_value(INPUT_SERVER,...) doesn't make much difference in information, so please use it as you like.


2022-09-30 20:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.