<?
#####
#
#   LoadFile.php
#
#   copyright 2001-2002, Kevin Lindsey
#
#####

#
#   Turn off escaping of special characters
#
set_magic_quotes_runtime(0);

#
#   This is a simple attempt to prevent the download of just
#   any file on our server
#
if ( eregi("\.svg$", $file) ) {

    #
    #   It's an SVG file so get the file's size
    #
    $size = filesize($file);

    if ( $start == -1 ) {

        #
        #   -1 is used to specify that the calling routing
        #   wants to know the size of the file that is
        #   being downloaded.  Tell 'em how big it is.
        #
        print $size;

    } elseif ( $start < $size ) {

        #
        #   Otherwise we are being asked for a chunk of the
        #   file
        #
        if ( ( $start + $length ) > $size ) {
        
            #
            #   Oops.  Asked for too many bytes from the
            #   current position.  Re-adjust to how much we
            #   really need to read.
            #
            $size = $size - $start;

        }

        #
        #   Open the file for reading.
        #   Really should be error checking from here
        #   on down.
        #
        $fh = fopen($file, "r");

        #
        #   Move to the position where we should begin
        #   reading
        #
        fseek($fh, $start);

        #
        #   Read the requested number of bytes and send
        #   those back to the calling routine
        #
        print fread($fh, $length);

        #
        #   All done.  Close the file
        #
        fclose($fh);

    } else {

        #
        #   The start position in the file is passed the
        #   end of the file.  That means we're all done.
        #
        print "done";

    }
} else {

    #
    #   Really should return some sort of violation error here
    #
    print "done: invalid doc type: $file, $start, $length";

}
?>
