View Full Version : Recent Upload
malcolmmatheson
08-11-2004, 09:57 PM
I have a file uploading script that allows users to upload files to my server.
I need a script that shows the most recent uploads (sorted by date) to my webspace. the files get uploaded to 4 folders in ../uploads
mlseim
08-11-2004, 10:47 PM
I don't know why I can't find anything like this searching the internet.
All I could find so far was a $20.00 script like this:
http://upoint.info/cgi/demo/ageindicator/index.htm
I'll keep looking until someone else offers a solution...
--Max--
mlseim
08-12-2004, 06:38 PM
Here's the snippet I was looking for ...
Enter your directory ($directory) and it will list your files by name,size,modification (days),accessed(days)
You can then do whatever sorting, comparing, etc. you want.
#!/usr/bin/perl
#######################################################
# The directory (folder) you want to examine (relative path from this script)
$directory = "../myfolder1";
chdir($directory) || die "cannot cd to $directory ($!)";
opendir(MYDIR, "./");
@myfiles = readdir(MYDIR);
closedir(MYDIR);
print "Content-type: text/html\n\n";
print "
<html>
<head><title>File List Example</title></head>
<body><table cellpadding='10' cellspacing='5'><tr>
<td>Filename</td><td>Filesize</td><td>Modified Days</td><td>Accessed</td></tr>
";
foreach (@myfiles) {
chomp;
printf("<tr><td>%12s</td> <td>%8d</td> <td>%12d</td> <td>%12d</td>\n", $_, -s, -M, -A);
}
print "</body></html>\n";
malcolmmatheson
08-13-2004, 12:38 PM
Looks good, but how do I sort it by date, and make links to the files?
Thanks in advance
mlseim
08-13-2004, 03:05 PM
Here's the snippet again, with the sort and link creation ...
Now, you need to make your own output, and maybe a loop to only display the first five files (or whatever) ... this enough of a 'skeleton' script to get you started. If you are new to Perl, this would be a good learning exercise for you.
Here's my favorite Perl learning resource site:
http://iis1.cps.unizar.es/Oreilly/perl/learn/index.htm
#!/usr/bin/perl
#######################################################
# The directory (folder) you want to examine (relative path from this script)
$directory = "../";
chdir($directory) || die "cannot cd to $directory ($!)";
opendir(MYDIR, "./");
@myfiles = readdir(MYDIR);
closedir(MYDIR);
#sort by field, where -M is the modification date.
@sorted = sort { -M $a <=> -M $b } @myfiles;
print "Content-type: text/html\n\n";
print "
<html>
<head><title>File List Example</title></head>
<body><table cellpadding='10' cellspacing='5'><tr>
<td>Filename</td><td>Filesize</td><td>Modified Days</td><td>Accessed</td></tr>
";
foreach (@sorted) {
chomp;
printf("<tr><td>%12s</td> <td>%8d</td> <td>%12d</td> <td>%12d</td></tr> \n", $_, -s, -M, -A);
$mod = ($_,-M); #example of extracting the modification date.
$siz = ($_,-s); #example of extracting the file size.
print "<tr><td>link: <a href='$directory$_' target='_blank'>$_</a></td></tr>\n";
}
print "</table></body></html>\n";
malcolmmatheson
08-15-2004, 03:10 AM
Ok, I have read tutorials and edited the following code to sort 1 DIRECTORY'S files by date. but how do I make it so it sorts files in MULTIPLE directories?
(by the way, taking out the '/A' makes it list the directories not files :( )
Thanks
#!/usr/bin/perl
use File::Find;
opendir(DIRLIST,'../htdocs/graphics/A');
@myfiles = readdir(DIRLIST);
closedir(DIRLIST);
#sort by field, where -M is the modification date.
@sorted = sort { -M $a <=> -M $b } @myfiles;
print "
<html>
<head><title>File List Example</title></head>
<body><table cellpadding='10' cellspacing='5'><tr>
<td>Filename</td><td>Filesize</td><td>Modified Days</td><td>Accessed</td></tr>
";
foreach (@sorted) {
chomp;
printf("<tr><td>%12s</td> <td>%8d</td> <td>%12d</td> <td>%12d</td></tr> \n", $_, -s, -M, -A);
$mod = ($_,-M); #example of extracting the modification date.
$directory = $File::Find::name;
$directory =~ s/htdocs\///i;
print "<tr><td>link: <a href='$directory$_' target='_blank'>$_</a></td></tr>\n";
}
print "</table></body></html>\n";
mlseim
08-18-2004, 05:06 AM
darn ...
I had it figured out to search a bunch of directories, sort them,
and display them ... but
then, I couldn't create the links because I wasn't able to determine
which directory each item came from ...
back to square one ... I think this is getting to be more Perl than I
have ability.
Does anyone else reading these threads have an idea how to do this?
--Max--
rockdoc
08-28-2004, 01:43 AM
The free script called "dirwrap" http://scripts.dmag.org/dirwrap/ will do the trick :thumbsup:
This script will not only display directory files in an attractive manner, but also has the option of sorting them by date.
It will even count the number of times the file has been downloaded!
I've been using it for 6 months now-it's a great script.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.