...

View Full Version : timeago... feature for uploaded file



pagedrop
07-13-2012, 08:29 AM
Hello,

I've been using a file manager script and wanted to modify the list view, so it can show time ago... for each uploaded file.

below is the code to view all the files in a directory where the files are uploaded.

But I tried using time()-filemtime(filename) but I'm not sure how to fit in the code...

could you please help on this. thank you in advance.


function get_dirlist_folders($userdir, $viewurl, $uploaddir, $formatted=true){
if(isset($_SESSION['username']))
{
/*
Delete a file or folder after the delete link has been clicked.
*/
if($_GET['delfile'])
{
if(isset($_SESSION['frienddir']))
{
if($_SESSION['perms'] == "rw")
{
$fileresult = unlink($userdir."/".$_GET['delfile']);
}
}
else
{
$fileresult = unlink($userdir."/".$_GET['delfile']);
}
}

//Reads all directories in the current folder and checks to make sure its valid
if(dirCheck($userdir))
{
$dh = opendir($userdir);
while ($file = readdir($dh))
{
$tempfilearray[] = $file;
}
closedir($dh);

natcasesort($tempfilearray); //sorts array alphabetically

$filearray = array_slice($tempfilearray, 0); //somewhat of a hack, reassigns array keys so directory list will be alphabetical


for($a=0;$a<count($filearray);$a++)
{
if(is_dir($userdir."/".$filearray[$a]))
{
$filenum++;
}
}

if($filenum != 2)
{
for($index=0; $index < count($filearray); $index++)
{
if($filearray[$index] != "." AND $filearray[$index] != "..")
{
if(is_dir($userdir."/".$filearray[$index]))
{
if($formatted)
{
if(isset($_SESSION['frienddir']))
{
if($_SESSION['perms'] == "rw")
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\" title=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/folder_rename.png\" alt=\"rename\" title=\"rename\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "/" . $filearray[$index] . "\">" . str_replace("_", " ", $filearray[$index]) . "</a></li>\n";
}
else
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "/" . $filearray[$index] . "\">" . str_replace("_", " ", $filearray[$index]) . "</a></li>\n";
}
}
else
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\" title=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/folder_rename.png\" alt=\"rename\" title=\"rename\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "/" . $filearray[$index] . "\">" . str_replace("_", " ", $filearray[$index]) . "</a></li>\n";
}
}
if(!$formatted)
{
echo "<option name=\"" . str_replace("_", " ", $filearray[$index]) . "\" value=\"" . str_replace("_", " ", $filearray[$index]) . "\">" . str_replace("_", " ", $filearray[$index]) . "</option>\n";
}
}

}
}
}
else
{
echo "<li>There are no directories in your account. Create one!</li>";
echo "<br>";
}
}
}
else
{
echo "<p>That directory is restricted for security purposes.</p>";
}
}

function get_dirlist_files($userdir, $viewurl, $uploaddir)
{
if(isset($_SESSION['username']))
{
if(isset($_SESSION['frienddir']))
{
$username = $_SESSION['frienddir'];
}
else
{
$username = $_SESSION['username'];
}
//Goes through directory and reads files and folders in that directory
if(dirCheck($userdir))
{
$dh = opendir($userdir);
while ($file = readdir($dh))
{
$tempfilearray[] = $file;
}
closedir($dh);

natcasesort($tempfilearray); //sorts array alphabetically

$filearray = array_slice($tempfilearray, 0); //somewhat of a hack, reassigns array keys so directory list will be alphabetical

for($a=0;$a<count($filearray);$a++)
{
if(! is_dir($userdir."/".$filearray[$a]))
{
$filenum++;
}
}
if($filenum != 0)
{
for($index=0; $index < count($filearray); $index++)
{
if($filearray[$index] != "." AND $filearray[$index] != "..")
{
if(! is_dir($userdir."/".$filearray[$index]))
{
if($_GET['dir']){
$fh = fopen($uploaddir.$username.$viewurl."/".$filearray[$index], "r");
$fileinfo = fstat($fh);
$kbsize = round(($fileinfo['size']/1024),2);
if(isset($_SESSION['frienddir']))
{
if($_SESSION['perms'] == "rw")
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\" title=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/rename.png\" alt=\"rename\" title=\"rename\"></a> <a href=\"edit.php?file=" . $username . $viewurl . "/" . $filearray[$index] . "\"><img src=\"img/edit.png\" alt=\"edit file\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&movefilebox=" . $filearray[$index] . "\"><img src=\"img/move.png\" alt=\"move\" title=\"move\"></a> ";
}
else
{
echo "<li>";
}
}
else
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\" title=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/rename.png\" alt=\"rename\" title=\"rename\"></a> <a href=\"edit.php?file=" . $username . $viewurl . "/" . $filearray[$index] . "\"><img src=\"img/edit.png\" alt=\"edit file\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&movefilebox=" . $filearray[$index] . "\"><img src=\"img/move.png\" alt=\"move\" title=\"move\"></a> ";
}
echo "<a href=\"readfile.php?file=" . $username . $viewurl . "/" . $filearray[$index] . "\"><strong>" . $filearray[$index] . "</strong></a> ";
if($kbsize<1024)
{
echo "(".round(($fileinfo['size']/1024),2)." KB) ";
}
else
{
echo "(".round((($fileinfo['size']/1024)/1024),2)." MB) ";
}

}
else
{
$fh = fopen($uploaddir.$username."/".$filearray[$index], "r");
$fileinfo = fstat($fh);
$kbsize = round(($fileinfo['size']/1024),2);
if(isset($_SESSION['frienddir']))
{
if($_SESSION['perms'] == "rw")
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/rename.png\" alt=\"rename\"></a> <a href=\"edit.php?file=" . $username . "/" . $filearray[$index] . "\"><img src=\"img/edit.png\" alt=\"edit file\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&movefilebox=" . $filearray[$index] . "\"><img src=\"img/move.png\" alt=\"move\" title=\"move\"></a> ";
}
else
{

}
}
else
{
echo "<li><a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&delfileconfirm=" . $filearray[$index] . "\"><img src=\"img/delete.png\" alt=\"delete\"></a> <a href=\"user.php?dir=".$_GET['dir']."&rename=".$filearray[$index]."\"><img src=\"img/rename.png\" alt=\"rename\"></a> <a href=\"edit.php?file=" . $username . "/" . $filearray[$index] . "\"><img src=\"img/edit.png\" alt=\"edit file\"></a> <a href=\"" .$reldir . "user.php?dir=" . $viewurl . "&movefilebox=" . $filearray[$index] . "\"><img src=\"img/move.png\" alt=\"move\" title=\"move\"></a>";
}
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id=\"$filearray[$index]\" href=\"readfile.php?file=" . $username . "/" . $filearray[$index] . "\">" . $filearray[$index] . "</a> ";
if($kbsize<1024)
{

echo "".round(($fileinfo['size']/1024),2)." KB ";

}
else
{
echo "".round((($fileinfo['size']/1024)/1024),2)." MB ";

}
}

}
}
}
}
else
{
echo "<p>You haven't uploaded any files yet. Click on the above upload button to start uploading your files with our new drag n drop feature!</p>";
echo "<br>";
echo "<br>";
}
}
else
{
echo "";
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum