/    Sign up×
Community /Pin to ProfileBookmark

[code=php]
$handle=opendir($upload_dir);
$filelist = “”;
$counter = 1;

while ($file = readdir($handle) && ($counter <=10) )
{

if(!is_dir($file) && !is_link($file))
{
//$filelist .= “<a href=’$upload_dir$file’>”.$file.”</a>”;
$filelist .= $file;
if ($DELETABLE)
{
$filelist .= ” <a style=’text-decoration:none; font-weight:bold’ href=’?del=$upload_dir”.urlencode($file).”‘ title=’delete’>x</a>”;
}

$filelist .= ” Added at “.date(“d-m H:i”, filemtime($upload_dir.$file))
.””;

$filelist .=”<br>”;
}
$counter = $counter +1;
}
[/code]

here is my attempt: but i keep getting errors ?
hint? suggestion?
Thanks!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MadamZuZuauthorMar 30.2007 — the error im getting is:

Warning: filemtime(): Stat failed for ../../forum/uploads/downloads/1 (errno=2 - No such file or directory) in /home/content/M/a/d/MadamZuZu/html/test/upload/upload1.php on line 105

line 105 is :

[code=php]
$filelist .= " Added at ".date("d-m H:i", filemtime($upload_dir.$file))
[/code]
Copy linkTweet thisAlerts:
@MadamZuZuauthorMar 30.2007 — shoot. it seems that as soon as i post, i figure out the problem... i think it's because while waiting for the reply, i relax and let myself think a little bit.
Copy linkTweet thisAlerts:
@MadamZuZuauthorMar 30.2007 — uugghh!!!!

the problem remains.

i got it to display 10 files, instead of all, but it shows 10 oldest files, how do i show 10 most recently updated???

Thanks!
Copy linkTweet thisAlerts:
@DARTHTAMPONMar 30.2007 — The problem is that readdir reads in order of file creation date.

The only way around this that I have been able to come up with so far is to add the file contents into an array and then make your output based on the last 10 rows of the array. This will work fine with a few files but if you get into 500 or more it will create alot of overhead. I do not like this solution but it will work.

Any of the gurus on this forum know of a differnt function to get around having to do this that will allow ordering?
Copy linkTweet thisAlerts:
@MadamZuZuauthorMar 30.2007 — thanks ?
Copy linkTweet thisAlerts:
@DARTHTAMPONMar 30.2007 — http://moongroup.com/pipermail/shell.scripting/2002-August/007745.html

this might help, im not sure since I have never done anything like this befor.
Copy linkTweet thisAlerts:
@MadamZuZuauthorMar 30.2007 — [code=php]
/************************************************************
* List Files
************************************************************/

$dir= opendir($upload_dir);
$basename = basename($upload_dir);
$fileArr = array();

while ($file_name = readdir($dir))
{
if (($file_name !=".") && ($file_name != ".."))
{
#Get file modification date...
#
$fName = "$upload_dir/$file_name";
$fTime = filemtime($fName);
$fileArr[$file_name] = $fTime;
}
}

# Use arsort to get most recent first
# and asort to get oldest first
arsort($fileArr);

$numberOfFiles = sizeOf($fileArr);
//for($t=0;$t<$numberOfFiles;$t++)
for($t=0;$t<10;$t++)
{
$thisFile = each($fileArr);
$thisName = $thisFile[0];
$thisTime = $thisFile[1];
$thisTime = date("d M y", $thisTime);
$filelist .= "<b>$thisName</b> $thisTime <p>";
}
closedir ($dir);
[/code]


it worked!!!!

Perfect!!!!

Thank you VERY MUCH!!!!!!!!!!!
×

Success!

Help @MadamZuZu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...