473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Script needed

Hi,

Im after a simple script to help sort my downloads.

Basically I have a downloads folder, and at the moment I have directory
browsing enabled so that i can download files.

What I want is to have a php script (index.php) that will parse the
files that it finds in downloads and create a nice page (using my
template and css). If it finds a directory in /downloads, then it
should create a 'group title' and all the files in that folder should
be grouped under that group title.

The important thing is that the ultimate links to the files themselves
need to clickable links to the files (ie, if you hover over the file
link the status bar shows blahblah.zip as the link), rather than to
another php file passing a variable (ie index.php?file=blah.zip). This
is because my server seems to stop downloads after 10mb unless the user
clicks on a file link.

Anyone know where I can get such a thing ?

Olly

Dec 15 '06 #1
1 1613
Hi,

You could install a file browser application, such as one of these, and
customize it to your needs:

www.ecosmear.com/relay/
www.rebelinblue.com/?fm

You could also write a script that uses opendir and readdir to print a
custom view of a directory. The script below does just this:

<?

//
// MyFileBrowser
//
// This class provides a simple file browser that lets
// users browse through a directory tree and access
// files as direct links. Customize the look as needed.
//
// Sample usage:
//
// $fb =& new MyFileBrowser('/physical/path', '/virtual/path');
// $fb->printDirectory();
//
// The first argument is the physical path of the directory
// you wish to browse. The second argument is virtual path of
// the directory on your web site.
//

class MyFileBrowser
{
var $sysRootPath;
var $virtualRootPath;

function MyFileBrowser($sysRootPath, $virtualRootPath = '.')
{
$this->sysRootPath = $sysRootPath;
$this->virtualRootPath = $virtualRootPath;
}

function printDirectory($path = null)
{
$buf = '';

if (is_null($path)) {
$path = isset($_GET['path']) ? $_GET['path'] : '/';
}
if (preg_match('/\.\./', $path)) {
trigger_error("Invalid path.", E_USER_ERROR);
return false;
}

$buf .= "<h1>File Browser</h1>";
$buf .= $this->printPath($path);

$parentPath = dirname($path);
if ($path != '/' && $path != '' && $path != '.') {
$dirPart = basename($parentPath);
if ($dirPart == '') {
$dirPart = 'Top';
}
$buf .= '<p style="font-size: 12px;">↑ <a href="' .
htmlentities($this->linkToDir($parentPath), ENT_QUOTES) .
'">Up to ' . htmlentities($dirPart) . '</a></p>';
}

$sysPath = $this->joinPath(array($this->sysRootPath, $path));
$dir = opendir($sysPath);

if (!$dir) {
$buf = false;
trigger_error("Failed to open \"$sysPath\".", E_USER_ERROR);
} else {
$entries = array();
while (($entry = readdir($dir)) !== false) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entries[] = $entry;
}

if (!sort($entries)) {
$buf = false;
trigger_error('sort', E_USER_ERROR);
} else {
$buf .= "<ul>";

foreach ($entries as $entry) {
$sysSubPath = $this->joinPath(array($sysPath, $entry));
if (is_dir($sysSubPath)) {
$buf .= $this->printSubDirectory(
$this->joinPath(array($path, $entry)));
} else {
$filePath = $this->linkToFile(
$this->joinPath(array($path, $entry)));
$buf .= "<li><a href=\"" .
htmlentities($filePath, ENT_QUOTES) .
"\">" . htmlentities($entry, ENT_QUOTES) . "</a></li>";
}
}

$buf .= "</ul>";
}

closedir($dir);
}

echo $buf;
}

function printPath($path)
{
$buf = '<p style="font-size: 20px; font-weight: bold;">Directory ';
$parts = preg_split('#[/\\\\]+#', $path, -1, PREG_SPLIT_NO_EMPTY);
array_unshift($parts, '/');

$curPath = '';
for ($i = 0; $i < count($parts); $i++) {
$part = $parts[$i];
$curPath = $this->joinPath(array($curPath, $part));
$url = $this->linkToDir($curPath);
$buf .= '<a href="' . htmlentities($url, ENT_QUOTES) . '" ' .
'style="font-size: 20px; font-weight: bold;">' .
htmlentities(($i == 0 ? 'Top' : $part), ENT_QUOTES) . '</a>';
if ($i < count($parts) - 1) {
$buf .= '<b/ </b>';
}
}

$buf .= '</p>';
return $buf;
}

function printSubDirectory($path)
{
$buf = '';

$sysPath = $this->joinPath(array($this->sysRootPath, $path));
$dir = opendir($sysPath);

if (!$dir) {
$buf = false;
trigger_error("Failed to open \"$sysPath\".", E_USER_ERROR);
} else {
$entries = array();
while (($entry = readdir($dir)) !== false) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entries[] = $entry;
}

if (!sort($entries)) {
$buf = false;
trigger_error('sort', E_USER_ERROR);
} else {
$buf .= "<p><li>";
$htmlName = htmlentities(basename($path), ENT_QUOTES);
$url = $this->linkToDir($path);
$buf .= "<p style=\"font-size: 20px; font-weight: bold;\">" .
"<a href=\"$url\">$htmlName</a></p>";
$buf .= "<ul>";

foreach ($entries as $entry) {
$htmlName = htmlentities($entry, ENT_QUOTES);
$sysSubPath = $this->joinPath(array($sysPath, $entry));
if (is_dir($sysSubPath)) {
$url = $this->linkToDir(
$this->joinPath(array($path, $entry)));
$buf .= "<li><a href=\"" . htmlentities($url, ENT_QUOTES) .
"\">$htmlName/</a></li>";
} else {
$filePath = $this->linkToFile(
$this->joinPath(array($path, $entry)));
$buf .= "<li><a href=\"" .
htmlentities($filePath, ENT_QUOTES) .
"\">$htmlName</a></li>";
}
}

$buf .= "</ul></li></p>";
}
}

closedir($dir);
return $buf;
}

function linkToFile($path)
{
return $this->joinPath(array($this->virtualRootPath,
preg_replace('#^[/\\\\]#', '', $path)));
}

function linkToDir($path)
{
$url = $_SERVER['PHP_SELF'];
$url = preg_replace('/([\?&])path=.*?(&|$)/', '\1', $url);
$c = $url[strlen($url) - 1];
if ($c != '?' && $c != '&') {
$url .= strrchr($url, '?') === false ? '?' : '&';
}
$url .= 'path=' . urlencode($path);
return $url;
}

function joinPath($parts)
{
$str = join('/', $parts);
$str = preg_replace('#/+#', '/', $str);
$str = preg_replace('#\\\\+#', '\\', $str);
return $str;
}
}

$fb =& new MyFileBrowser(dirname(__FILE__));
$fb->printDirectory();

?>

Regards,

John Peters

Oliver Marshall wrote:
Hi,

Im after a simple script to help sort my downloads.

Basically I have a downloads folder, and at the moment I have directory
browsing enabled so that i can download files.

What I want is to have a php script (index.php) that will parse the
files that it finds in downloads and create a nice page (using my
template and css). If it finds a directory in /downloads, then it
should create a 'group title' and all the files in that folder should
be grouped under that group title.

The important thing is that the ultimate links to the files themselves
need to clickable links to the files (ie, if you hover over the file
link the status bar shows blahblah.zip as the link), rather than to
another php file passing a variable (ie index.php?file=blah.zip). This
is because my server seems to stop downloads after 10mb unless the user
clicks on a file link.

Anyone know where I can get such a thing ?

Olly
Dec 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Fox | last post by:
I merged and modified these script which work perfectly fine as long as I use server.execute to access the VBS part (which is itself in another ASP file). When these I use a session variable to...
6
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!--...
6
by: Richard Trahan | last post by:
I want a js function to call a Perl script residing on a server. The Perl script will return a string, to be used by the js. Pseudo code: <script> stringvar = perlfunc_on_server(stringarg)...
4
by: Pimpalicious Nerd | last post by:
'Ello mates. I'm currently learning PHP from a book that I got at a Barnes and Noble (the one near times square in new york; one of my friends got kicked out for somehow managing to move ALL the...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
3
by: Steve Powell | last post by:
Hi, Can anyone help me with this one? How can I remove script registered by RegisterClientScriptBlock ? If I add another script with the same name, is the first one overwritten or it's just...
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.