A small front-end file browser for Pulse

Hi there,
I had a client who wanted to manage many files (pdf,doc,etc.) and folders at his Intranet. I made a simple file browser for Pulse. Maybe you find this useful.

Create a new block: sb_browser.txt
Create a new folder: /content/pages/files
Create a new page: /content/pages/files/index.txt containing {{block:sb_browser}}

Now you can create folders and subfolders at /content/pages/files and copy your files into them. Always copy index.txt to every folder. I did it via ftp.
Link to file browser would be: yourwebsite.com/files/index. Style the results with a little CSS.

One issue: I had to disable Pulse autobackup because it took too long with hundreds of files.

Here comes sb_browser.

<?php
// where are we?
$directory = "content/pages".dirname($_SERVER["REQUEST_URI"])."/";
$directory = urldecode($directory);
$folder    = dirname($_SERVER["REQUEST_URI"])."/";
$top       = (basename(dirname($folder)));
$top       = urldecode($top);
$header    = basename($folder);
$header    = urldecode($header);

//read all files 
$files = glob($directory . "*");
//sort
natcasesort($files);
?>

<div class="textblock">
<h1><?= $header ?></h1>

<?php 
// one step up
if(!empty($top))
{  ?>
<p>Back to: 
<a href="<?= dirname($folder) ?>/index"><?= $top ?></a></p>
<?php }  ?>

<table class="sortable block">
<tr>
<th>Name</th>
<th>Type</th>
</tr>

<?php
foreach($files as $file)
{
//is it a folder?
if(is_dir($file))
{ ?>

<tr>       
<td class="folder"><a href="<?= $folder ?><?= basename($file) ?>/index"><?= basename($file) ?></a></td>
<td>Folder</td>
</tr>
       
<?php 
}  
}
foreach($files as $file)
{
// filetype?
$ext = strtolower(substr($file, strrpos($file, '.') + 1));
// let filetypes pass
if(($ext == 'pdf') || ($ext == 'doc') || ($ext == 'docx') || ($ext == 'xls') || ($ext == 'xlsx'))
{  ?>
    
<tr>       
<td class="file"><a href="/<?= $file ?>" target="_blank"><?= basename($file) ?></a></td>
<td><?= $ext ?></td> 
</tr>    
    
<?php } } ?>
</table>
</div>
2 Likes

This is a great tip and addition - thanks for sharing @dirk!
:slight_smile:

Here you 'll find a demo:
http://dirkdigital.com/Files/index
:slight_smile:

3 Likes

This topic was automatically closed after 11 hours. New replies are no longer allowed.