/home/a/aquarion/sites/www.aquarionics.com/epistula/chapters/attachment.inc.php
All my code (That is, anything not in the "Others" list on the right) is BSD licenced.
You can also view this page as text/plain or colour-coded source
<?PHP
/*******************************************************************************
Chapter - Postcards
********************************************************************************
Postcards from Elysian. This could be fun.
$Id: attachment.inc.php,v 1.1.1.1 2004/05/16 17:39:14 aquarion Exp $
$log$
*******************************************************************************/
// We've been called from Epistula, so we have $wanted, an array containing the requested file path.
// wanted[0] will be "attachment", so wanted[1] should be an id...
if (!is_numeric($wanted[2])) {
panic("Datatype Error", $wanted[1]." doesn't look like a number to me");
}
// so it is, and we can get the file.
$results = safequery("select * from attachment where id = ".$wanted[2]);
if (mysql_num_rows($results) == 0) {
$page->title = "Attachment Error";
$page->debug = $wanted[1]." isn't a valid attachment ID";
$page->status = 404;
$panic = true;
} else {
$row = mysql_fetch_assoc($results);
}
/* Row:
mysql> describe attachment;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| id | bigint(20) | | PRI | NULL | auto_increment |
| page_id | bigint(20) | YES | | NULL | |
| page_type | tinytext | YES | | NULL | |
| file | tinytext | YES | | NULL | |
| description | tinytext | YES | | NULL | |
| mimetype | tinytext | YES | | NULL | |
| size | int(10) unsigned | | | 0 | |
+-------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)*/
if ($panic) {
} elseif (! file_exists($_EP[webdir]."/".$row['file'])) {
$page->title = "Attachment Error";
$page->content = "Failed to find the file \"".$_EP[webdir]."/".$row['file'] ." :-|";
} else {
if ($wanted[1] == "dl") {
header("Content-Type: ".$row['mimetype']);
header("Content-Length: ".$row['size']);
readfile ($_EP[webdir]."/".$row['file']);
$finalOutput = true;
} elseif ($wanted[1] == "embed") {
//<object data="mlk.mov" type="video/quicktime" title="martin luther king's "i have a dream" speech" width=150 height=150>
$page->title = $row['description'];
#$page->newObject($_EP[webdir]."/".$row['file'], $row['mimetype'], $row['description'], $row['size']);
$page->content .= $page->item("<object"
." data=\"/".$_EP[webdir]."/".$row['file']."\""
." type=\"".$row['mimetype']."\""
." title=\"".$row['description']."\""
." standby=\"/assets/images/e_wait.png\""
#." width=\"150\""
#." height=\"150\""
.">"
#.$row['description']
."</object>");
}
}
?>
Using a heavily customised version of Tom's PHPCode2ValidXHTML Thing