0

I've been tackling this for 2 days now without success. Yesterday I posted a question here to which I received a couple of suggestions which I didn't really understand.

I asked for clarification and have had no response yet.

Either:

  1. I'm not explaining myself very well.
  2. The solution can't be found
  3. Anybody who may be able to help has not yet seen it.

OK - here goes - nice 'n' simple....

I'm using a XAMPP server on WIN7 with FireFox.

  1. At my browser address bar I can type : file:///C:/xampp/htdocs/folder1/subfolder1/, which is sort of OK

  2. I put the following code inside an anchor in a page and run it from XAMPP/htdocs folder : href="folder1/subfolder1/">Go to subfolder1, yields similar sort of result

  3. At my browser again I type : file:///C:/folder2/subfolder2/ and have the same sort of result as 1.

My question is what should my anchor look like to get to C:/folder2/subfolder2/

Is there something I am not understanding?

If someone out there can post a 'fiddle' or show me an example I'm sure I could work through this

Community
  • 1
  • 1
Acoustic Jack
  • 107
  • 3
  • 14
  • 1
    The second answer to your first question (the one with the 5 slashes) sounds pretty reasonable to me (without having tested that, I have no MS-Windows system to do so). Keep in mind that such a reference must be considered a security issue which is why probably most browsers prevent you from doing exactly that. – arkascha May 12 '15 at 18:31

2 Answers2

0

This doesn't work by default because allowing someone to access the local file system that the server is running on from outside the computer would be a security breach. You can type it in the URL field because your browser is running on the same machine and has access to the drive.

If you want to open it from a link inside of an HTML file from a client, you'll need to write a program that runs on the server (PHP is a good language to use) that would receive the request and display the folder contents. Of course this wouldn't a very safe thing to do, but the URL might look like this:

http://yourserver/showfolder.php?dir=c:/folder1/subfolder2

Then you just need to write showfolder.php and have it use the parameter dir and respond with html to display the folder contents. Again, though it's possible to do this, you should think hard about why you want to and what information you're making available outside of the machine that others should not see.

I think the thing you're not understanding is what program is interpretting the url in each case. Whey you type file://... into the browser, it's the browser doing the work of finding the content on disk and showing it to you. When you use a url, that's an http request which asks your server to do the work.

Always Learning
  • 5,510
  • 2
  • 17
  • 34
  • Can you give me some idea what showfolder.php would look like. For instance is it 'readdir' inside a 'while' ? – Acoustic Jack May 13 '15 at 10:40
  • You can probably find lots of examples by googling. Here's one: http://www.liamdelahunty.com/tips/php_list_a_directory.php – Always Learning May 13 '15 at 13:38
  • I have done some more testing with some funny results. I tried to copy here but too many characters. Maybe I'll try in 2/3 attempts – Acoustic Jack May 14 '15 at 12:04
  • You say.. 'you should think hard about why you want to and what information you're making available outside of the machine that others should not see.' I agree that security is always an issue so perhaps you can give me an opinion... My scenario is a small office with 6/7 clients currently using a mapped drive (E:) to an area on the server. All in the same building using straightforward cabling (maybe too much info here). I have setup XAMPP on this server and they login to my html on the intranet with 10.0.0.XXXXXXX etc. They can also login from the internet using WAN IP etc. – Acoustic Jack May 14 '15 at 12:04
  • This is up and running and working fine. They sometimes have to manually create a new folder on drive E: I have done some research and think I can automate this process. The problem I cannot seem to solve is getting access to this folder on E: in my html. I am writing all this as I would be grateful for some opinions from those who have experience in these matters. Also is there nowhere other than these forums to find out this stuff??? How did you guys/gals learn it??? Back to my immediate issue..... ================================ – Acoustic Jack May 14 '15 at 12:05
  • This is your suggetion for the URL (typo at folder1).. http://yourserver/showfolder.php?dir=c:/folder1/subfolder2 This is the first part the PHP code from liamdelahunty.com/tips/php_list_a_directory.php which I have copied to C:\xampp\htdocs\showfolder.php.. etc. This is part of html.. Go to subfolder2 – Acoustic Jack May 14 '15 at 12:06
  • When I run it the array of files/folders is printed but NOT c:/folder2/subfolder2 The list is from my htdocs at C:\xampp\htdocs\ !!! In fact whatever dir I send from html to PHP I get the same list ie. showfolder.php?dir=c:/ showfolder.php?dir=c:/foo.txt (does not exist) showfolder.php?dir=c:/folder2/bar.jpg/ Looks like I'm nearly there but not quite!!! – Acoustic Jack May 14 '15 at 12:07
  • Again I am on Win 7 and using FireFox 38.0 – Acoustic Jack May 14 '15 at 12:09
  • Instead of `$myDirectory = opendir(".")` you should be passing the folder supplied as the `dir` parameter. Using `"."` will have it open the current working directory that the `PHP` program is running in. You want the value passed in the `http` request. Try this instead: `opendir($_GET['dir'])` – Always Learning May 14 '15 at 13:09
  • I used $_GET... and almost worked. The subfolder has just 1 file, New Text Document.txt. address bar is 'localhost:1338/showfolder.php?dir=c:/folder2/subfolder2' The output is 3 columns 1st with filename, the 2nd is 'Warning: filetype(): Lstat failed for New Text Document.txt in C:\xampp\htdocs\showfolder.php on line 32' and the3rd is 'Warning: filesize(): stat failed for New Text Document.txt in C:\xampp\htdocs\showfolder.php on line 35' ....... If I click on filename to open it the new windows says 'Object not found' and the address bar is 'http://localhost:1338/New Text Document.txt' – Acoustic Jack May 14 '15 at 18:16
  • I have a screen dump but cannot put it here – Acoustic Jack May 14 '15 at 18:16
  • Try a filename without spaces in it. If that shows proper data then you will have to figure out how to handle names with spaces. Clicking on a link will not work because you've given a url that won't resolve to that file in the server. If you want people to be able to click on it, you'll have to construct a url that your server will understand is a request for the file, and provide it. – Always Learning May 14 '15 at 18:19
0

Your question is meant mainly by Apache Creating alias and directory listings. In your Apache conf at C:\xampp\apache\conf\httpd.conf add new alias like the following:

Alias /subfolder2 C:/folder2/subfolder2
<Directory "C:/folder2/subfolder2">
  Options FollowSymLinks +Indexes
  Order Allow,Deny
  Allow from All
  AllowOverride All Indexes Options
</Directory>

By this way you can get listing the contents of C:/folder2/subfolder2/ just as simple as

<a href=http://localhost/subfolder2">Subfolder2 Contents</a>
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • Thanks for your help but I tried something like this yesterday. # # Options +Indexes # AllowOverride None # Order allow,deny # Allow from all # Your suggestion #Alias /subfolder2 C:/folder2/subfolder2 # # Options FollowSymLinks +Indexes # Order Allow,Deny # Allow from All # AllowOverride All Indexes Options # In both cases when I take out the '#'s XAMPP will not start! – Acoustic Jack May 13 '15 at 09:34
  • I'm assuming I have to stop apache, make changes then start apache – Acoustic Jack May 13 '15 at 09:36
  • Yes it is. You have to restart Apache. – SaidbakR May 13 '15 at 10:45
  • How do I put a newline in this comment ????????????? If I hit 'Enter' the comment is posted??? As I said above, Apache will not start if I add your code..................... Alias /icons/ "C:/xampp/apache/icons/" Options Indexes MultiViews AllowOverride None Require all granted – Acoustic Jack May 13 '15 at 12:12
  • I'm pretty sure this is how to solve the problem, I just have to figure out how to get Apache restarted after adding the Alias and – Acoustic Jack May 13 '15 at 12:14
  • @user3392854 The code is not rendered well in the comment, so try to write the code in an online editor such as [tag:jsfiddle] – SaidbakR May 13 '15 at 12:20
  • The Apache is not able to start due to mistake in conf file. you may know it from the Apache log. – SaidbakR May 13 '15 at 12:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77728/discussion-between-user3392854-and-ss). – Acoustic Jack May 13 '15 at 14:41