[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ProgSoc] CGI / HTML Answer



 Greetings,

 I know.. I know.. I forwarded a slug message to progsoc yesterday. 
 Sorry about that.  I'm blaming NT (still).

 To make up for it, I induced a small degree of boredom today, and
 for the first time in several years, wrote a very small program to
 address whatshisname's query about displaying the 10 most recently
 accessed PDF files in a directory, to a web page.

 My chosen language was PHP3 (so you can test it on ftoomsh - woo! -
 thanks to whoever installed PHP3 here), and my time starts now.

 It's annotated a bit, and hopefully no mail readers will attempt to
 interpret from this bit onwards as an html document.  {blech}  As
 observed in the code, no files in the directory will cause an error,
 no files that match the reg-expression match will also cause an
 error, and there's plenty of extraneous info presented that you can
 remove from the code (it's there so you can trust it's doing the
 right thing).  Remember, more information from www.php3.org, and
 also /usr/doc/php3 (on a decent Linux box. :)  Other than that, you
 should be able to cut and paste the rest of this message, and it'll
 work hunky-dory.
 
 Cheers,
 Jedd.

 PS.  And if you don't like the nomenclature, indenting, or other
 aspects of my coding style, you can byte me.  ;)
 
 <----------------------------- snip here ----------------------------->


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="vi">
   <META NAME="Author" CONTENT="jedd@nospam.zev.isg.otc.com.au">
   <TITLE>ICC - Admin HOWTOs</TITLE>
</HEAD>

<?php
	// this function compares timestamps of files - used by usort() later
	function cmpfiletime ($a,$b) {   
		return ( (filemtime($a) < filemtime($b)) );
		}
	// ----- end of cmpfiletime() function

	$d = dir(".");
	$x = 0;
	while ( $entry=$d->read() ) {
		// eregi : case-insensitive substring search,
		// modify the 'pdf' string for other purposes.
		// (if no *pdf* files exist, you'll get an error)
		if (eregi ("a", $entry, $regs) ) 
			$fullarray[$x++]=$entry;
		}
	$d->close();

	// usort : sexy sort function that takes a user-defined function
	// as the sort criteria, as the second parameter.
	usort ($fullarray, cmpfiletime);

	echo "<center>";
	echo "Showing top ten documents, from total of $asize";
	echo "<br>- - - - - - - - - - - - - - - - - - - - - - -<br>";
	echo "</center>";

	$asize =  count ($fullarray);
	if ($asize > 11 )
		$asize = 11;
	for ( $x=0 ; $x != $asize ; $x++) {
		$ralph = date ("j M Y H:i", filemtime($fullarray[$x]));
		echo "Modified date of $ralph  &nbsp; ";
		echo "<a href=\"$fullarray[$x]\">$fullarray[$x]</a><br><p>\n";
		}
?>

</BODY>
</HTML>


 <------------------------ stop snipping about here ------------------------>
--
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.

This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>