While using nodejs, How can I access files outside root directory? - html

I'm making a nodejs page to show as an management page.
I need to access a directory outside root directory.
But I can't access with relative path.
Directory example is like this.
C:\resultDirectory\projectA
C:\resultDirectory\projectB
C:\reportDirectory\ProjectA
C:\reportDirectory\ProjectC
C:\NodejsRootDIrectory
What I want to do for now is Access a file in subdirectory of "C:\resultDirectory\projectA". But at the end, I need to access them all. So I can't make webpage root to project A's directory.
What I've dont to access was relative path. sample is
$('#report').load("../../../ProjectA/Daily/DailyReport_191001_151843.html");
I've checked number of "../" and tried add and subtract several times.
For now, this is only code relative to access files.
$('#report').load("../../../ProjectA/Daily/DailyReport_191001.html");
When I check chrome's error, there is only 404 error. the browser can't find out the file I want to see.

Related

Live server is not loading my images but when I open my file manually ex:index.html, my images are fully loaded

<div class="slide__Show1">
<h2>It's More Than Just A Sport</h2>
<p>Get back on the field in style!</p>
<img src='../E-commerce/IMG/Soccer.jpeg'>
</div>
Live server works as a real (remote) server, and looks for the image like a real server would do: Not on your local machine, but relative to the project root on your "server".
When you open a local HTML file on your computer/in your browser, it is able to look for the image file locally anywhere on your computer, and thus is a bit easier to satisfy.
So there's a slight difference which types of URLs/paths you can use in a local file and a file that is supposed to work on a server.
In your case, you need to use either an absolute path or a relative path.
Absolute path: https://examplesite.com/assets/img/soccer.jpg
Relative path: /assets/img/soccer.jpg
Your relative path goes one level UP (out) from the root folder of your project (because of ../) and searches for a file that is probably outside your website folder, in the E-commerce directory.

Set absolute path for root directory in HTML on local filesystem

How can I use absolute paths in my website while testing on my local filesystem? I know that I can use / to access the root directory of my website. However, this works only when my website is on the server. I want to be able to use absolute paths on my local filesystem so that I can do proper testing before uploading.
Is there a way to set a variable to a root directory in HTML? Something similar to Linux where you can define a variable WEBPATH=/home/user/website. Thus I can use e.g src="WEBPATH/folder/file.html for all the files I use in my website and I can modify WEBPATH depending on whether I am testing locally or using the server root folder.
I am open to other workarounds as well.
I'm assuming you're using a file url to access your HTML in the browser, in which case an easy way to get absolute paths working is by using a local webserver to serve your site.
If you have Python 3 installed, you can run python3 -m http.server from the command line at your web root, and it will serve your site at localhost:8000.

How to do I create a cgi-bin directory?

I need a cgi-bin but I can't find one when I am connected on Filezilla or cPanel, it's just public_html and that's it.
What do I do? I have looked online and it says that I need to use a command line but I have no clue how I would do that!
The "cgi-bin" directory does not exist until you create it with your FTP program at the top level of your Web site directory. From the perspective of your FTP program, it's just a normal directory (folder) that you can create, but it's treated differently by the server because of its special name.
Open your Filezilla program and connect to your website.
When you are in your top-level directory, (Where you see "public_html")
Right-click anywhere in the the window and select "create directory."
Simply name the directory "cgi-bin"
You're done!

Cannot Access Web Page on Apache 2.2 Server

I've made a simple web page for one of my classes, and uploaded it to an Apache server on campus, from which I'm to view and take a screenshot of.
Before trying to view the page I created a sub-directory on the server to put my HTML file. Once the upload was complete, I changed the permissions on the file to -rwx---r-x and on the sub-directory folder to drwx---r-x.
However, I'm not able to view the page. I keep getting a message saying 403: Forbidden. You do not have sufficient privileges to view this site on this server.
Is there anything else that I need to do to the file and/or folder to be able to view the web page?
Who is the owner and the group of the file?
You probably need to change the file permissions to -rwxr--r-- and directory to drwxr-xr-x

Link to a file in a higher level folder

I'm having troubles serving a document which is in a higher level than my root folder.
<a href='../../home/folder/document.docx'>Proposal</a>
In the browser the above gets interpreted as:
http://localhost/home/folder/document.docx
I cannot see the browser going up in the folders and then the answer I get is:
Not Found
The requested URL /home/folder/document.docx was not found on this server.
I have tried in Firefox and Chrome, it happens the same. I am using Apache Web Server on a Linux machine.
Any help will be appreciated.
You can not redirect your visitors to a file outside of your document root (where you have your index.html).
People can't see files higher than where http://localhost/ ends up in.
A solution would be to put that .docx inside of your document root (where your index.html is in).
You can however let PHP serve the file using the readfile function.
But don't forget that www-data would need to have access to the file you're serving.