httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ras...@madhaus.utcs.utoronto.ca
Subject Re: conditional HTML
Date Sun, 11 Feb 1996 23:10:36 GMT
> Processing instructions are a little less ugly, but less well defined by 
> SGML.  Basically they are tags which begin with a ?, and it's left up to 
> the browser or spec to specify what to do with them.  I.e.
> 
> <?IF cond="condition"> 
> <?ELSIF>
> <?ENDIF>

I have written a server-side html-embedded scripting language called
PHP/FI that is used by quite a few sites on the Net now.  I by no means
think it should become any sort of standard, but I do think it serves
as a good example of what can be done with such a language.  

I went back and forth on the question of what to use as the initiator
tag as well.  I ended up going with the SGML PI tag, even though most
browsers have no clue what to do with them if they do manage to slip
through unparsed.  Here is some example code which displays a list of
files in a table.  The actual file information is read right out of
a directory with opendir() and readdir() calls in a while loop.  
A regular expression match is done on the filenames to figure out if
they are valid (.gz or .zip) and an appropriate icon is used to
represent the file.  Then at the bottom an RFC-1867 File Upload form
is presented and users who know the upload password may go ahead
and upload files directly to the upload directory.  More information
on PHP/FI can be found at http://www.io.org/~rasmus if you are interested.
The site is currently being completely re-written and moved to
http://www.vex.net/php, so you may want to check there as well.  The
actual file upload page is only on vex.net.

<?
	$file_dir = "files";
	opendir($file_dir);
	$entry = readdir();
	$i=0;
	while($entry);
		$dir[$i] = $entry;
		$type[$i]=0;
		if(reg_match(".*\.gz$",$entry));	
			$type[$i] = 1;
			$i++;
		elseif(reg_match(".*\.zip$",$entry));	
			$type[$i] = 2;
			$i++;
		endif;
		$entry = readdir();
	endwhile;
	$num = $i>
	<center><table border=2>
	<?if($num==0); echo "<caption>No Files!</caption><p>";
	elseif($num==1); echo "<caption>1 File</caption><p>";
	else; echo "<caption>$num Files</caption><p>"; endif>
	<tr><th></th><th>Filename</th><th>Size</th><th>Date</th>
	<th>Description</th></tr>
	<?$i=0;
	while($num && $i < $num);
		if($type[$i] == 1)>
			<tr><td align=center>
			<img src="/php/gifs/filegz.gif" hspace=2></td>
		<?elseif($type[$i] == 2)>
			<tr><td align=center>
			<img src="/php/gifs/filezip.gif"></td>
		<?endif>
		<td align=center>
		<?echo "<a href=\"/php/files/$dir[$i]\">$dir[$i]</a></td>";
		echo "<th>";
		echo fileSize("$file_dir/$dir[$i]");
		echo "</th><th>";
		echo Date("M d/y H:i:s",fileMtime("$file_dir/$dir[$i]"));
		echo "</th>";
		$fp = @fopen("$file_dir/$dir[$i].info","r");
		echo "<td align=left>";
		if($fp != -1);
			$line = fgets($fp,100);
			while($line);
				echo $line;
				$line = fgets($fp,100);
			endwhile;	
		else;
			echo "none";
		endif;
		echo "</td></tr>";
		$i++;
	endwhile;
	echo "</table></center>">
	<p><hr>
	<center>
	<form action="/php/receive.phtml" 
		enctype="multipart/form-data" method=POST>
	Upload password: <input type="password" name="pw"><br>
	<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
	Filename: <input type="file" name="filename"><br>
	Description<br>
	<textarea name="description" rows=3 cols=30></textarea><br>
	<input type="submit" value=" Send File ">
	</form></center>


Mime
View raw message