Directory listing(help!)

Started on the old forum in November 2011 · view the original in the archive · old links redirect here

6 replies · 429 views · started 15 years ago · 1 min read

3 participants
softwarefreak Senior · 349 posts #1

Hello

I'm using this code for directory listing in a college project

<?php
$mode = $_GET['mode'];
$dir = $user."/".$mode;

if($handle = @opendir($dir))
{ 
    while($file = readdir($handle))
    { 
        if(is_file($dir.'/'.$file)) 
			//$time = filemtime($file);
            echo "<tr><td width='80%'><div class='sub_alt'><img src='bg/Message.png'/> <a href='read.php?mode=".$mode."&user=".$user."&token=".$pass."&message=".$file."'><b>".ucfirst(basename($file,'.html'))."</b></a></div></td><td><a href='del.php?mode=".$mode."&user=".$user."&token=".$pass."&message=".$file."'><div class='footer'><font color='red'><b>(x)</b></font></a></td></tr>";
		}
		
    closedir($handle);
} 
?>

I'm getting errors while using filemtime() or filectime() functions,how to correct the errors?

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

arnage Lead · 811 posts #3

U need to format the time stamp for example like this:

echo 'Moded at '.date('F d Y H:i', filemtime($file));
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #5

Can u please explain the problem? I don't see main.php page from Demo project and don't want to register anywhere. Or at least make a screen shot.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
softwarefreak Senior · 349 posts #6

Bro,dis link main.php

Demo project

I wana sort the files wid time & also to show the time beside filenames

I've used the filemtime() as u've said but getting errors

Warning: filemtime() [function.filemtime]: stat failed for hey.html in C:\wamp\www\codes\login\main.php on line 15

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

arnage Lead · 811 posts #7

Well as for that it basicly goes like this,

first to read content of the folder and create the array of files:

$handle = @opendir($folder);
while ($file = readdir($handle)) {
if (is_file($dir.'/'.$file) {
$filesarray[] = $file;
}
}
closedir($handle);

... and here in $filesarray are the files. Now to sort the array how u want use sort(), ksort() or with their flags like SORT_NUMERIC, u choose what. For example:

sort($filesarray, SORT_NUMERIC);

.. and now is just left to loop and display files:

foreach ($filesarray as $key => $file) {
    echo '#'.$key.'. File: '.$file.', Moded at '.date('F d Y H:i', filemtime($file));
}

But in the first post there are some issues, basename() used for example and looking those vars like $mode, $user, $pass in combination with this ain't gonna work how it should so if i get it right u will need some different slightly complicated way.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close