Terry,

>From your post, i'm not exactly sure what you want to do. You talk about 
simply uploading an image file. Are you also saving the name of the 
image in the database? Do you also want the capability to edit this? In 
what way, just on the database or also on the server.

Also from your post, it *seems* to me it might help to study up a little 
on the cffile tag. Forgive me if i have that wrong, but there are a few 
attributes that you need to know about in this situation, "nameconflict" 
is one, "accept" is the other.

Also, it's important to realize that the server takes the path to the 
file you want to upload that you enter in the form field and changes it 
to something else, yes, i think with a .tmp extension. CFAS makes a 
structure called "file" available that you can work with to get to the 
post-upload information you may need.

As far as FB3 goes, i put all the upload business in an act file. i 
include here the code from one of mine to get you going. i'm kind of 
settling on separating out the file uploads (and deletes) into a 
separate function, so this is just upload, no fileName save. then later, 
i pull the filenames off the server using cfdirectory and provide a list 
of already uploaded files that the user can choose from, and that's 
where the file name (and path) gets associated with a db record. you 
could adapt this to continue on to a query that saves the 
#File.ClientFile# variable to a database.

Here's the act file that the form with the upload field hits when you 
click the submit button. I'm not going to be online much in the next 2 
days, so if you have more questions, maybe someone else might pick them 
up.

good luck ...

******
<cfparam name="caught" type="boolean" default="false">
<cftry>
<cfif strFileName is not "">
<cffile action="UPLOAD" filefield="strFileName" 
destination="#imagePath#" nameconflict="ERROR" accept="image/tiff, 
image/*, image/gif">
</cfif><!--- , application/pdf --->
<cfcatch type="Any">
<cfset caught = 'true'>
<cfoutput>
<table border="0"><tr><td width="400">
<b>An Error has occurred when attempting to upload this file:</b><p>
<cfif CFCATCH.Detail CONTAINS 'already exists'>
The file '#File.ClientFile#' could not be uploaded because a file of 
that name already exists on the server. Either rename the file and try 
again if this is different image with the same name, or use the existing 
file if you discover that what you need is already uploaded.
<cfelseif CFCATCH.Detail CONTAINS 'MIME type'>
Only image files (specificially JPG or GIF files) can be uploaded to the 
server in this section. If you are attempting to upload a PDF file, 
please use the Upload PDF link.
<cfelse>
An unknown error occured. If the error persists, please contact the 
website Administrator.
</cfif>
</td></tr></table>
</cfoutput>
</cfcatch>
</cftry>
<cfoutput>
<cfif IsDefined('File.ClientFile')>
<cfif File.FileWasSaved>
The file <b>'#File.ClientFile#'</b> was successfully uploaded.
<META HTTP-EQUIV="refresh" CONTENT="2; 
url=#self#?fuseaction=#XFA.continue#">
<cfelseif File.FileWasSaved EQ 'False' AND caught EQ 'false' >
The file #File.ClientFile# was not successfully uploaded. Please try 
again. If the error persists, please contact the website Administrator.
</cfif>
<cfelse>
<cfif caught EQ 'false'>
<table border="0"><tr><td width="400">
<b>An Error has occurred when attempting to upload this file:</b><p>
It seems that the file you entered does not exist. Please make sure that 
the file name path and file name are correct. We suggest that you use 
the "Browse" button to find the file on your computer.
</td></tr></table>
</cfif>
</cfif>
</cfoutput>

*******
Terry Hogan wrote:
> I a newbie working on my first FB3 project.  I'm sure I'll have a lot of 
> questions as I go along and here's my first:
> 
> I have a form that includes a file upload.  I only want to allow gif, 
> jpeg and pdf uploads.
> 
> At first I tried parsing the file extension from the field value 
> (uploadFile) before I actually processed the upload, but that often (not 
> always???) came through as a *.tmp file.
> 
> So then I thought I'd use Cftry/Cfcatch around the Cffile statement in 
> my act_fileUpload template, using the accept attribute to limit mime 
> types.  That sort of worked, but the message I put in cfcatch did not 
> display within the parent's layout.
> 
> What I really wanted was to send 'em back to the form with a message 
> that only the above file types are permitted like I do for other data 
> validation errors.  I tried  <cfinclude 
> template="#self#?fuseaction=ListingFileMgmt.FileUploadError"> and 
> different hard-coded variations thinking I'd create a separate 
> fuseaction for handling the error, but I kept getting errors finding the 
> template.  (I haven't worked with Cfcatch that much--can you use 
> cfinclude?)
> 
> I then tried <cflocation 
> url="#self#?fuseaction=ListingFileMgmt.FileUploadError> and at least 
> that got me back to  FBX_Switch, but I lost all the attributes variables 
> with the reload.
> 
> I finally got it to work by passing all the necessary variables as URLs 
> in cflocation--luckily it was a short form.
> 
> Although I got it to work my questions are:
> 1.) What's the best way to handle a situation like this in FB3?
> 2.) Why does the upload file field value sometimes sometimes post as 
> *.tmp?  i.e.: C:\WINDOWS\TEMP\ACFB100.TMP when the actual file is 
> blah.jpg?
> 3.)  Why doesn't the message I include in CFcatch display within the 
> parent layout?
> 4.) When using cfcatch, can you use cfinclude?
> 5.)  If you cfcatch an error, should you pass it to a fuseaction in 
> FBX_Switch?  If so, how?  I realize this depends on what you're 
> catching, but I'm trying to keep all my program flow within the Switch 
> file.
> 
> Thanks for any input.
> 
> Terry
> 
> 
> 

==^================================================================
This email was sent to: [email protected]

EASY UNSUBSCRIBE click here: http://topica.com/u/?bUrFMa.bV0Kx9
Or send an email to: [EMAIL PROTECTED]

T O P I C A -- Register now to manage your mail!
http://www.topica.com/partner/tag02/register
==^================================================================

Reply via email to