405 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			405 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 | 
						|
<html xmlns="http://www.w3.org/1999/xhtml">
 | 
						|
<head>
 | 
						|
<title>GT::SQL::File - adds file upload and download abilities to GT::SQL</title>
 | 
						|
<link rev="made" href="mailto:root@penguin.office.gossamer-threads.com" />
 | 
						|
 | 
						|
<style type="text/css">
 | 
						|
/* $MVD$:fontset("Untitled Font Set 1","ARIEL","HELVETICA","HELV","SANSERIF") */
 | 
						|
/* $MVD$:fontset("Arial","Arial") */
 | 
						|
/* $MVD$:fontset("Arial Black","Arial Black") */
 | 
						|
/* $MVD$:fontset("Algerian","Algerian") */
 | 
						|
 | 
						|
 | 
						|
body {
 | 
						|
    background-color: white;
 | 
						|
    font-family: Verdana, Arial, sans-serif;
 | 
						|
    font-size: small;
 | 
						|
    color: black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p {
 | 
						|
    background-color : white;
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    background-color : white;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : medium;
 | 
						|
    font-weight : bold;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h3 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : maroon;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h5 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h6 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ul {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ol {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
li {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
th {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
td {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dd {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dt {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
code {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-H1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : 14.0pt;
 | 
						|
    background-color : transparent;
 | 
						|
    background-image : none;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 12.0pt;
 | 
						|
    color : blue;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indent {
 | 
						|
    font-family : "Verdana, Arial, sans-serif";
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indent {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre.programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE-programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE {
 | 
						|
    font-size : 9.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : normal;
 | 
						|
    font-size : 9.0pt;
 | 
						|
    color : black;
 | 
						|
    margin-left : 6.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 10.0pt;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-BODY {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
</style>
 | 
						|
 | 
						|
 | 
						|
</head>
 | 
						|
 | 
						|
<body style="background-color: white">
 | 
						|
 | 
						|
<p><a name="__index__"></a></p>
 | 
						|
<!-- INDEX BEGIN -->
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li><a href="#name">NAME</a></li>
 | 
						|
	<li><a href="#description">DESCRIPTION</a></li>
 | 
						|
	<ul>
 | 
						|
 | 
						|
		<li><a href="#creating_a_new_file_column">Creating a new FILE Column</a></li>
 | 
						|
		<li><a href="#inserting_into_the_column">Inserting into the Column</a></li>
 | 
						|
		<li><a href="#retreiving_from_column">Retreiving from Column</a></li>
 | 
						|
	</ul>
 | 
						|
 | 
						|
	<li><a href="#copyright">COPYRIGHT</a></li>
 | 
						|
	<li><a href="#version">VERSION</a></li>
 | 
						|
</ul>
 | 
						|
<!-- INDEX END -->
 | 
						|
 | 
						|
<hr />
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h1><a name="name">NAME</a></h1>
 | 
						|
<p>GT::SQL::File - adds file upload and download abilities to GT::SQL</p>
 | 
						|
<p>GT::SQL::File::Fh - basic file object</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="description">DESCRIPTION</a></h1>
 | 
						|
<p>GT::SQL::File is not created directly by the user. This module is an
 | 
						|
internal module for GT::SQL to provide the abilty to upload/download 
 | 
						|
files into a database column (or so it seems).</p>
 | 
						|
<p>GT::SQL::File::Fh is often accessed by the user as well as created 
 | 
						|
by the user whenever the user wants to store a file in the database.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="creating_a_new_file_column">Creating a new FILE Column</a></h2>
 | 
						|
<p>When a new table is created or a column is converted into 'FILE' 
 | 
						|
type, two things are created. First a column of type text which will 
 | 
						|
save the name of the file that is being stored. Secondly, a 
 | 
						|
piggy-back table will be greated under the name 
 | 
						|
``parent_table_name_File''. This new table will store the location of 
 | 
						|
the uploaded/stored file and various associated file attributes.</p>
 | 
						|
<p>To create a new file table, include a column something like the
 | 
						|
following.</p>
 | 
						|
<pre>
 | 
						|
    File_Col_Name => {</pre>
 | 
						|
<pre>
 | 
						|
                # common parameters
 | 
						|
                       pos  => 2, 
 | 
						|
                       type => 'FILE',</pre>
 | 
						|
<pre>
 | 
						|
                # location of the directory where
 | 
						|
                # all the files should be saved
 | 
						|
                       file_save_in => '/tmp',</pre>
 | 
						|
<pre>
 | 
						|
                # the method all the files are saved
 | 
						|
                # 'hashed', or 'simple'
 | 
						|
                #
 | 
						|
                # Defaults to hashed, and stores files in:
 | 
						|
                #   file_save_in/hashed_letter/ID
 | 
						|
                # Simple stores files in:
 | 
						|
                #   file_save_in/ID_OwnName.OwnExt
 | 
						|
                       file_save_scheme => 'hashed',
 | 
						|
                     } ...</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="inserting_into_the_column">Inserting into the Column</a></h2>
 | 
						|
<p>Once you have the table created, to insert:</p>
 | 
						|
<pre>
 | 
						|
    # Include all the modules
 | 
						|
    use GT::SQL;
 | 
						|
    use GT::SQL::File;
 | 
						|
    
 | 
						|
    # First create a file object pointing to the file
 | 
						|
    $f = GT::SQL::File->open('/path/to/file.txt');
 | 
						|
    
 | 
						|
    # Then create a table object
 | 
						|
    $DB = GT::SQL->new('path/to/defs');
 | 
						|
    $tbl = $DB->table();
 | 
						|
    
 | 
						|
    # Create the record
 | 
						|
    # the file field can also be GT::CGI::Fh type
 | 
						|
    $rec = {
 | 
						|
        File_Column => $f,
 | 
						|
        # ... and all the other columns
 | 
						|
    };</pre>
 | 
						|
<p># optionally, if you know the path to the file, you can provide
 | 
						|
# a scalar ref of the path and the module will autoload
 | 
						|
# the values
 | 
						|
# simple scalar values will be dropped
 | 
						|
    $rec = {
 | 
						|
        File_Column => \``/path/to/file.txt''
 | 
						|
        # ... and all the other columns
 | 
						|
    };
 | 
						|
</p>
 | 
						|
<pre>
 | 
						|
 | 
						|
    # Then to store the file
 | 
						|
    $id = $tbl->add( $rec );</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="retreiving_from_column">Retreiving from Column</a></h2>
 | 
						|
<p>When a file has been stored. A standard select will only return
 | 
						|
the name of the file.</p>
 | 
						|
<p>To get a filehandle, taking the previous example, if we know the
 | 
						|
unique id, you can do the following.</p>
 | 
						|
<pre>
 | 
						|
    $fh = $tbl->file_info( 'File_Column', $id );</pre>
 | 
						|
<p>You can use this file handle just like any other, however hidden
 | 
						|
behind are special functions that can be used as follows:</p>
 | 
						|
<pre>
 | 
						|
    print "Content-type: ", $fh->File_MimeType(), "\n\n";
 | 
						|
    print <$fh>;</pre>
 | 
						|
<p>The following is a partial list of special functions you may access.</p>
 | 
						|
<pre>
 | 
						|
 
 | 
						|
    Method             Returns
 | 
						|
    ------             -------
 | 
						|
    File_Name          the basic filename
 | 
						|
    File_Directory     path to the file
 | 
						|
    File_MimeType      mimetype of the file
 | 
						|
    File_Size          site of the file
 | 
						|
    File_RelativePath  the permuted file and directory without root
 | 
						|
    File_URL           if possible, the URL to the requested file</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="copyright">COPYRIGHT</a></h1>
 | 
						|
<p>Copyright (c) 2004 Gossamer Threads Inc.  All Rights Reserved.
 | 
						|
<a href="http://www.gossamer-threads.com/">http://www.gossamer-threads.com/</a></p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="version">VERSION</a></h1>
 | 
						|
<p>Revision: $Id: File.pm,v 1.60 2004/08/28 03:53:43 jagerman Exp $</p>
 | 
						|
 | 
						|
</body>
 | 
						|
 | 
						|
</html>
 |