Link to a file in a higher level folder - html

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.

Related

Mediawiki: Links to open local files on the server doesn't work

I have MediaWiki installed on a synology server. I would like to create a link on the wiki that would allow opening of files on the same server.
Here are the steps I did to achieve this:
Added $wgUrlProtocols[] = "file://"; in LocalSettings.php
A test file on the server: file://myServerName/path/to/file/test.txt. Putting this URL in my chrome browser directly opens the file.
Create a page in MediaWiki with a link to this file using [[file://myServerName/path/to/file/test.txt]]
When I click on the generated wiki page, nothing happens. However when I hover on top of the link, it shows the correct URL.
Can someone please point out what additional steps I need to do to get this working?
The file:// protocol points to the file on your computer. I'm not fully sure, but I think you cannot use it to retrieve file from a different machine (read my comment below about samba shares).
From quick research it looks like Chrome browser blocks requests with file:// protocol, But browsers like IE should allow you to open those files. It is done because of security reasons so the malicious site cannot open local files without your permission. You might bypass that by installing a special plugin in Chrome (look for Enable file links)
Instead of using file protocol, make those files available via Synology WebStation, and then create links that point to the file via webstation (not via path on the server). With that approach, links attached on your MediaWiki pages will work as those will be regular links.
If you don't use the WebStation, you might also try with ftp:// links (use the FTP service), or link to samba shares - that's where the file:// protocol might work, but again - I'm not sure and I cannot test it as I do not use windows.
I think that the safest/easiest/fastest way is to expose those files via WebStation.
Source: https://en.wikipedia.org/wiki/File_URI_scheme
The file URI scheme is a URI scheme defined in RFC 8089, typically used to retrieve files from within one's own computer.

How to create link in HTML that download that file

I have http://192.168.230.237:20080 Server
file located on "/etc/Jay/log/jay.txt"
I tried with "http://192.168.230.237:20080/etc/Jay/log/jay.txt" this link gives me "404 NOT Found"
Here I can I link my file to link
Your HTTP server will have a configuration option somewhere (Apache HTTPD calls it DocumentRoot) which determines where http://example.com/ maps onto the filesystem of the computer.
Commonly this will be /var/www/.
Unless you change it to / (which would expose your entire filesystem over HTTP and is very much not recommended), you can't access arbitrary files on the computer.
/etc/ is used to store configuration information for software installed on the computer. It should almost never be exposed outside the computer.
The best solution to your problem is probably:
Look at the configuration of your HTTP server and identify the document root (e.g. /var/www/)
Move your website files to that directory
If you really want to expose files under /etc via HTTP then you could also change the document root.
Your webserver might also support features like Apache HTTPD's Alias directive which allows you to map a URL onto a file that can be outside the DocumentRoot.

How do I load local files to a front-end html5 runing on apache2 localhost

I can't realize how to load a video located on my Desktop on a front-end code I have in my localhost runing on apache2.
I tried: file:///localhost/home/Desktop/video.mp4 , but It doesn't work because for sure, I'm not right.
Thanks!
file protocol loads local files, first you have to use the http protocol, then apache will look for files in your document root directory so all paths will be relative to the document root, so first you have to set the correct document root, then use the correct protocol.
it would be like http://localhost/video.mp4

Basic HTML - does relative path to a sub-folder (using the directory name) work on a desktop?

I am doing some basic HTML exercises on a Mac OS 10.6.6.
Say I am here:
rootfolder/index.html
and I want to go here:
rootfolder/subfolder/index.html
I understand I can use the relative path to make a link:
link to subfolder
^ this works for me in my browser.
And if I wanted to shorten the href, I could just do this:
link to subfolder
When I click the short version in my browser, the link takes me to the folder on my desktop (not to the page in my browser)
I'm wondering, do the files need to be in a web host environment for
the short version to work in a browser?
When /bob/ => /bob/index.html works, it is generally because the server has listed it as its directory index, e.g. with Apache...
DirectoryIndex index.html index.php
...meaning in the request of a folder, it will first look up to see if an index.html or index.php exists (in that order).
So if you are running it from the folders of your local filesytem (i.e. on the file: protocol), it has no server and does not know that a blank directory should request index.html.
The serving of index.html (or index.cgi or default.asp or whatever) when requesting a url that points to a directory is done by the server, not the browser. It is usually done as a result of configuration setting.
It's neither a property of HTML nor a property of urls.
If your browser doesn't serve index.html — and I don't know any that do — then you've answered your own question.
Mac OS comes with Apache (the most commonly-used open-source web server) pre-installed. You can set it up by going to System Preferences, choosing the "Sharing" preference pane, and then checking the box to turn on Personal Web Sharing.
Once you've turned on Personal Web Sharing, http://addressofyourcomputer/~yourusername/ will point to the Sites directory in your user's folder in Mac OS (i.e., /Users/yourusername/Sites/). With Apache running, if you go to http://addressofyourcomputer/~yourusername/subfolder/, it will in fact serve up /Users/yourusername/Sites/subfolder/index.html if there is an index.html file in that subfolder.
Without turning on Personal Web Sharing, though, there is no server running, and so your browser is really just directly accessing your computer's filesystem. As a result, when you ask for a folder, it literally returns you that folder, whereas Apache server knows the convention that /subfolder/ is really a request for /subfolder/index.html and will re-direct you accordingly.
The default page setting/redirection works only on web servers. The browser do not have intelligence(?) for such redirection. So the second option will not work.

html showing contents of folder

i am creating a web page to show the contents of a folder so that people can view the files and download them if needed.
Click here to view Folder
But i wanna do this without any coding what so ever, i found this code which lets me view files.
The problem i am facing is that when i double click the html page and open it this hyperlink works and i get what i need but when i access the page through a server (IIS 7) then the hyperlink does nothing ?
am i to set some permissions or what ?
can someone tell me what im doing wrong ?
The link will work when the file you want to download is on your own personal computer, which in your case is true if you're just showing the HTML file locally. It won't be true for users visiting your website from another computer though.
If you want to serve the file on a server, you need to link to the path on the server itself, that is, if the file is in C:\inetpub\wwwroot\test_pages, your A HREF looks like this:
Click here to view Folder
Offcourse, this will work for simple files. For folders, you need to enable the webserver to show directory contents by enabling Directory Browsing.
There are security implications of linking to a local file from an online source. It works when the page is held locally but when on a server it puts a stop to it.
You can also use linux build-in command Tree, in example below you can see that i only want to add files that are matching .tar.gz or .zip or .tar.bz2
tree -P "*.tar.gz|*.zip|*.tar.bz2" -h -D --dirsfirst -r -H . > index.html;
You can also add a custom css to the page for a better looking output.
Straighforward and highly secure since the result is only html
as you use windows you can use www.cygwin.com to emulate a linux environement