473,662 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1647
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 $virtualRootPat h;

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

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($pat h);

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

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

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($sysSub Path)) {
$buf .= $this->printSubDirect ory(
$this->joinPath(array ($path, $entry)));
} else {
$filePath = $this->linkToFile(
$this->joinPath(array ($path, $entry)));
$buf .= "<li><a href=\"" .
htmlentities($f ilePath, ENT_QUOTES) .
"\">" . htmlentities($e ntry, ENT_QUOTES) . "</a></li>";
}
}

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

closedir($dir);
}

echo $buf;
}

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

$curPath = '';
for ($i = 0; $i < count($parts); $i++) {
$part = $parts[$i];
$curPath = $this->joinPath(array ($curPath, $part));
$url = $this->linkToDir($cur Path);
$buf .= '<a href="' . htmlentities($u rl, 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 printSubDirecto ry($path)
{
$buf = '';

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

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(ba sename($path), ENT_QUOTES);
$url = $this->linkToDir($pat h);
$buf .= "<p style=\"font-size: 20px; font-weight: bold;\">" .
"<a href=\"$url\">$ htmlName</a></p>";
$buf .= "<ul>";

foreach ($entries as $entry) {
$htmlName = htmlentities($e ntry, ENT_QUOTES);
$sysSubPath = $this->joinPath(array ($sysPath, $entry));
if (is_dir($sysSub Path)) {
$url = $this->linkToDir(
$this->joinPath(array ($path, $entry)));
$buf .= "<li><a href=\"" . htmlentities($u rl, ENT_QUOTES) .
"\">$htmlNa me/</a></li>";
} else {
$filePath = $this->linkToFile(
$this->joinPath(array ($path, $entry)));
$buf .= "<li><a href=\"" .
htmlentities($f ilePath, ENT_QUOTES) .
"\">$htmlNa me</a></li>";
}
}

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

closedir($dir);
return $buf;
}

function linkToFile($pat h)
{
return $this->joinPath(array ($this->virtualRootPat h,
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(d irname(__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
3990
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 pass an email address from the database. I have had timeout problems and buffer problems and as I understand it, maybe a problem with changing the session variable too many times in one session. So I tried putting the two scripts on one page. When...
6
3520
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
15887
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) document.write(stringvar) </script> Can stringvar above be a url?
4
1672
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 bibles to the fiction section...lol...but that's another story). Its a good book, very easy to learn with, but the only trouble has been my attention span and neverending lust for video games. XD Anyways, I was browsing through some forums...
0
3221
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 converted/developed with VB.NET. What I want from debugging is to be able to step into the methods in the DLLs called from ASP scripts using Visual Studio .NET. Background: For typical script debugging issues, you can read and follow the two documents on...
3
3126
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 skipped? -- Steve Powell
3
2481
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 <div id="datetime"></div> tags, the text shows up, but the javascript output being sent to those some divs doesn't seem to want to work. It should be showing up in the middle of the content pane, just below the first table box. (set by .css) Here's...
1
47445
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.