Hi Mark,
I had some issues reply via email - and find I can;t attach files here
either... so here it is inline...
--=-=-=-=-=-=--=-=
Not sure if this is going to be much good to you or not,
But I have attached the file-add form and submit that we use here.

You might be able to hack it up for your own purposes.

(note we submit the file into the database as opposed to using the
file system, but  the checking all works and should help with your 0
file check.)

-=--=-=-
<!---
$Date: 2009-03-02 02:58:14 +1100 (Mon, 02 Mar 2009) $
$Author: awaddell $
$Revision: 6578 $
$HeadURL: http://192.168.10.95/svn/palcare/trunk/nz/mp/patient/scandocadd.cfm
$

Copyright (c) 2008. PalCare Pty. Ltd.
--->

<!--- check for a valid session --->
<cfif not isdefined("session.username")>
        <!--- there is no valid session. relocate to a custom error page --->
    <cflocation url="noSession.cfm">
<cfelse>
        <script language="javascript" type="text/javascript">
                function close_me()
                {
                  window.opener.location.href = window.opener.location.href;
                  window.opener.location.reload(true);
                  window.close();
                }
        </script>

        <cf_simple>
        <cfinclude template="qry_scandocTypeSELECT.cfm">

                <!--- Attachments information / variable declaration  /array
construction --->

                <!--- check if the array exists already --->
                <cfif NOT isdefined('session.filearray')><!--- if not, create 
it (2
dimensions) --->
                        <cfset session.filearray = arrayNew(2)>
                </cfif>

                <cfparam name="session.var_numfilesadded" default="0">

                <!--- set the Max file size to 10 MB --->
                <cfset var_filesizebytes = 10485760>

                <cfset file_name="">
                <cfset file_type="">
                <cfset file_description="">
                <cfset the_file="">
                <cfset file_size="">
                <cfset documentTypeid="">
                <cfset file_inserted_by="">
                <cfset file_insert_date="">

                <link rel="stylesheet" href="style.css" />

                <script language="javascript" type="text/javascript">
                        //javascript function captures the filename for use on 
the next
page add_file_action.cfm
                        //This is required as the filename gets made into 
"templocation/
tempfilename.tmp" and is thus unusable
                        //         for insertion into the DB as the filename 
and filetype.

                        function setfilename(formvalue)
                        {
                                document.forms['addfile']['thefile'].value = 
formvalue;
                        }
                </script>

                <cfoutput>
                        <cfform action="scandocaddsubmit.cfm" method="post" 
name="addfile"
enctype="multipart/form-data">
                                <!--- set the button text based on if there is 
a file or not --->
                                <cfif ArrayLen(session.filearray) GT 0>
                                        <cfset buttontext1 = "Finish"><!--- set 
to finish if a file
exists in the array --->
                                <cfelse>
                                        <cfset buttontext1 = "Cancel"><!--- set 
to Cancel if the array is
empty--->
                                </cfif>

                                <table width="100%">
                                        <tr align="center">
                                                <!--- Centre align the INNER 
Table --->
                                                <td>
                                                        <table width="90%" 
border="0" cellpadding="0" cellspacing="0">
                                                        <tr>
                                                                <th 
align="center" colspan="3">Supplementary Information -
Attached Files</th>
                                                        </tr>
                                                        <tr>
                                                                <td 
colspan="3">&nbsp;</td>
                                                                <!---space row 
--->
                                                        </tr>
                                                        <tr align="left" 
valign="top">
                                                                <!--- see 
javascript comments for why / how this ONCHANGE
function works --->
                                                                <td 
colspan="3"><strong>Please Choose a File to attach to this
patient's Record (Limit of 10MB per file)</strong><br />
                                                                        <input
                                                                                
type="File"
                                                                                
name="formfilename"
                                                                                
size="40"
                                                                                
onchange="javascript:setfilename(form.formfilename.value)" /
>
                                                                        <input
                                                                                
type="hidden"
                                                                                
name="thefile"
                                                                                
id="thefile" />
                                                                        <br />
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td 
colspan="3">&nbsp;</td>
                                                        </tr>
                                                        <tr align="left" 
valign="top">
                                                                <td colspan="3">
                                                                        
<strong>File Description</strong><br />
                                                                        <cfinput
                                                                                
name="file_description"
                                                                                
type="text"
                                                                                
required="yes"
                                                                                
message="The file description may not be left blank and
SHOULD contain useful information to assist with future searching"
                                                                                
value=""
                                                                                
size="50"
                                                                                
maxlength="200">
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <!--- Spacer 
Row --->
                                                                <td 
colspan="3">&nbsp;</td>
                                                        </tr>
                                                        <tr>
                                                                <td colspan="3">
                                                                        
<strong>Document Type</strong><br />
                                                                        
<cfselect
                                                                                
name="documenttypeid"
                                                                                
value="documenttypeid"
                                                                                
display="documenttypedesc"
                                                                                
query="qry_scandocTypeSELECT"
                                                                                
required="true"
                                                                                
message="The Document Type must be completed">
                                                                        
</cfselect>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td 
colspan="3">&nbsp;</td>
                                                        </tr>
                                                        <tr align="left">
                                                                <td 
colspan="3"><strong>Please be patient while we check your
file...</strong> </td>
                                                        </tr>
                                                        <tr>
                                                                <!--- Spacer 
Row --->
                                                                <td>&nbsp;</td>
                                                        </tr>
                                                        <tr>
                                                                <!--- Spacer 
Row --->
                                                                <td>&nbsp;</td>
                                                        </tr>
                                                        <tr align="left">
                                                                <td>
                                                                        <!--- 
NEXT Button ... proceed to ACTION Template --->
                                                                        <input
                                                                                
name="submit"
                                                                                
type="submit"
                                                                                
value="Add File" />
                                                                        <!--- 
CANCEL/FINISH button --->
                                                                        <input
                                                                                
name="back"
                                                                                
type="button" onclick="javascript:close_me()"
                                                                                
value="#buttontext1#" />
                                                                </td>
                                                        </tr>
                                                        <tr align="left">
                                                                <td>
                                                                        <hr />
                                                                        
<strong>Files Added:</strong> #session.var_numfilesadded#<br /
>
                                                                        <br />
                                                                        <cfif 
ArrayLen(session.filearray) GT 0>
                                                                                
<cfloop from="1" to="#ArrayLen(session.filearray)#"
index="y">
                                                                                
        <!--- Array Position 2 is the Filename --->
                                                                                
        <em>#session.filearray[y][2]#</em><br />
                                                                                
</cfloop>
                                                                        </cfif>
                                                                </td>
                                                        </tr>
                                                        </table><!--- Close 
INNER Table --->
                                                </td>
                                        </tr>
                                </table><!--- Close OUTER Table --->
                        </cfform><!--- End the form --->
                </cfoutput>
        </cf_simple>
</cfif><!--- end of session checking --->


=--=-

<!--- check for a valid session --->
<cfif not isdefined("session.username")>
        <!--- there is no valid session. relocate to a custom error page --->
    <cflocation url="noSession.cfm">
<cfelse>

        <!--- set the Max file size to 10 MB --->
        <cfset var_filesizebytes = 10485760>

        <!--- initialise the variable we will use to determine if an error
has occurred or not --->
        <cfset fileerror = 'false'>

        <!--- Check for a valid file name --->
        <cfif form.formfilename neq ""><!--- check to see if the filename was
entered. --->
                <cfset file_name = getFileFromPath(theFile)> <!--- set the file 
name
--->
                <cfset file_type = listLast(file_name,".")> <!--- set the doc 
type
--->

                <cfif file_name eq #file_type#>
                        <!--- because of the way we obtain the file extension 
from the
filename, if they are the same
                                        then a file extension was not provided. 
alert the user to this
fact and ask them to correct it --->
                        <script language="javascript" type="text/javascript">
                                alert('You have chosen a filename without a 
valid file extension.\n
\nPlease ensure the file you add has an extension!');
                                history.back();
                        </script>

                        <cfabort>
                </cfif><!--- end of extension check --->

        <!--- filename was not entered, alert the user to this fact and ask
them to correct it --->
        <cfelse>
                <script language="javascript" type="text/javascript">
                        alert('The filename may NOT be left blank.\n\nUse the 
BROWSE button
to correct this!');
                        history.back();
                </script>

                <cfabort>
        </cfif><!--- end of filename check --->

        <!--- there is no error. continue processing --->
        <cfif fileerror eq "false">
                <!--- Increment FilesAdded var so that the cffile can work --->
                <cfset session.var_numfilesadded = session.var_numfilesadded + 
1>

                <!--- Try to create the file in the servers memory, Check for 
the
following errors while trying to
                                add to the server's memory.
                                        0 byte size file
                                        GT than max file size (10 MB)
                                if an error occurs return to add file window 
--->

                <cftry>
                        <!--- read the file into the server's RAM.--->
                        <cffile
                                action="READBINARY"
                                file="#form.formfilename#"
                                
variable="session.attached_file#session.var_numfilesadded#">

                        <!--- Set the variables that allow us to evaluate the 
actual file
--->
                        <cfset filetest = "session.attached_file" &
#session.var_numfilesadded#>
                        <cfset filetest2 = evaluate(#filetest#)>

                        <!--- Check for file size of 0 Bytes --->
                        <cfif len(filetest2) eq 0>
                                <cfthrow
                                        type="nofile"
                                        message="Invalid File. Please use the 
BROWSE button to correct
this.">
                        </cfif>

                        <!--- Check for file size of Greater than 10MB --->
                        <cfif len(filetest2) GT #var_filesizebytes#>
                                <cfthrow
                                        type="bigfile"
                                        message="File Size is greater than 10 
MB.">
                        </cfif>

                        <!--- if a fileerror occurred then display the error 
and go back to
the form. --->
                        <cfcatch type="any">
                                <cfset fileerror = 'true'>
                                <cfset session.var_numfilesadded = 
session.var_numfilesadded - 1>
                                <cfoutput>
                                        <script language="javascript" 
type="text/javascript">
                                                alert('#cfcatch.message#');
                                                history.back();
                                        </script>
                                </cfoutput>
                        </cfcatch>
                </cftry>

                <!--- if there was no error (fileerror eq false, then place all
variable values into the array.
                                NOTE: The actual array's contents are added 
into the DB by a file
add function in JOBS.CFC --->

                <cfif fileerror eq 'false'>
                        <!--- set up the session variables required for the 
array --->
                        <cfset thefile = "#form.thefile#">
                        <cfset file_desc = #form.file_description#> <!--- set 
the file
description --->
                        <cfset file_name = getFileFromPath(theFile)> <!--- set 
the file
name --->
                        <cfset file_type = listLast(file_name,".")> <!--- set 
the doc type
--->

                        <!--- now write the variables to the arrary ready for 
multiple file
addidtion--->
                        <cfset 
session.filearray[#session.var_numfilesadded#][1] =
"#form.formfilename#">
                        <cfset 
session.filearray[#session.var_numfilesadded#][2] =
"#file_name#">
                        <cfset 
session.filearray[#session.var_numfilesadded#][3] =
"#file_type#">
                        <cfset 
session.filearray[#session.var_numfilesadded#][4] =
"#file_desc#">
                        <cfset 
session.filearray[#session.var_numfilesadded#][5] = "#len
(filetest2)#">
                        <cfset 
session.filearray[#session.var_numfilesadded#][6] =
"#form.documenttypeid#">

                        <!--- return to the add_file  template--->
                        <cflocation url="scandocadd.cfm" >
                </cfif><!--- End FileError IF STATEMENT --->
        </cfif><!--- End Validation IF STATEMENT --->
</cfif><!--- end of session checking --->
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to 
cfaussie+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to