help with links to files within html / php

Associate
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
I have the following code that generates links to files within a folder structure

Code:
<!DOCTYPE html>

<?php
//$base = "Docs/";         //reference to local website location
$dirs = array_map("basename", glob($base . "*", GLOB_ONLYDIR));
$directory = isset($_GET['directory']) && in_array($_GET['directory'], $dirs) ? $_GET['directory'] : "";
?>

<head>
<title>Bury DMS</title>
<link rel="stylesheet" type="text/css" href="resources/mystyle.css" />
</head>


<html>
<body>


<div id="header-left">
	<img src="resources/logo.gif" alt="Big Boat" />
	<br>
</div>

			
<div id = "content">		
	<br>
	<form action="" method="GET">
	<select id="directories" name="directory" onchange="this.form.submit()" class="selectClass">
	<option value="">Select folder from the dropdown list...</option>
	<?php
		foreach($dirs as $val) 
		{
		echo '<option ' . ($directory == $val ? 'selected="selected" ' : '') . 'value="' . $val . '">' . $val . "</option>\n";  
		}
	?>
	</select>
	</form>	
	<p><b><i>Click on the document below to open it</i></b></p>
	<p>
	<?php
	if(is_dir($base . $directory))
	{
	foreach(glob($base . $directory . "/*.pdf") as $file) 
		{
		echo '<a href="' . $file . '">' . basename($file, ".pdf" ) . '</a><br>' . "\n";
		}
	}
	?>
	</p>
<div>

</body>
</html>

The generated links appear as:

http://dms.local/Docs/PB02/1100 Equipment Loading.pdf

However, when I change the target directory to one on our network share I get a file not found

i.e. changing to this line of code

Code:
$base = "//ken-ads1/groups/LNP/2 - JIB's & Procedures/0 - Jib's and Procedures/";

generates links like:-

http://ken-ads1/groups/LNP/2 - JIB'...ures/010 - General/180 - Flats and Tapers.pdf

I have tried changing the line generating the links to use the file protocol e.g.
Code:
echo '<a href="file://' . $file . '">' . basename($file, ".pdf" ) . '</a><br>' . "\n";

or

Code:
echo '<a href="file:///' . $file . '">' . basename($file, ".pdf" ) . '</a><br>' . "\n";

These both generate links like

file://ken-ads1/groups/LNP/2%20-%20JIB's%20&%20Procedures/0%20-%20Jib's%20and%20Procedures/010%20-%20General/180%20-%20Flats%20and%20Tapers.pdf

which don't open when the links are clicked but will open when I paste the link into the address bar

What am I doing wrong?
 
Associate
OP
Joined
4 Apr 2003
Posts
1,805
Location
Manchester
I am now gathering this is a security restriction. Tried a chrome extension which allows it and the last code example above works.

Is there any way around this without extensions or moving the files within the site structure?
 
Back
Top Bottom