Aquarionics

/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 &quot;i have a dream&quot; 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

Nicholas 'Aquarion' Avenell is a web developer in London, you can find out more about him or how to get in touch.

There are more Articles, Projects, Journal Entries, Photographs and things that defy description here, too.

If you're looking for something specific, there are Calendar & Category -based lists of everything.

And if you want to follow stuff that appears here, try a Syndication Feed, or the generic Feed of everything.


Aquarion's last Twitter was: [updating]
Twitter last updated


© 2000 to 2008 inclusive Nicholas Avenell
All comments are the property of their creators, published with permission
(Unless otherwise indicated, the opinions and sentiments expressed on this site are those of the author and not of any organisation of which he is an affiliate, including his employer. Caveat Lector, E&OE. sigh)
0.497 seconds, 1 queries, 2.61Mb on Sat, 11 Oct 2008 06:12:44 +0000, Not cached
Generated by Epistula Version 2.0.3