• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

problem with multiple cffile upload.

Community Beginner ,
Jun 01, 2011 Jun 01, 2011

Copy link to clipboard

Copied

Hello;

I am trying to program a small manager that will allow someone to upload 3 files, an image, pdf, and vcf files. I don't get any errors, BUT when I upload, the pdf file writes in as true to the db, it does upload the file, but I can't figure out why It's writting true and not the file name. I think I only need anothe rpair of eyes.. I can't figure it out. Can anyone help me out, and maybe see what I missed? I'll put in the form fields from the edit page and the query for the upload. So you get the idea.


Edit page:

<cfform action="Action.cfm" method="post" name="projects" id="projects" enctype="multipart/form-data">
<cfif isDefined("URL.ID")>
    <cfinput type="hidden" name="ID" value="#variables.ProjectID#">
    <cfinput type="hidden" name="oldimage" value="#MYFile#">
    <cfinput type="hidden" name="oldPDF" value="#MYPdf#">
    <cfinput type="hidden" name="oldVCF" value="#MYVfile#">
  </cfif>

<cfinput type="file" name="MYFile" id="MYFile">

<cfinput name="MYPdf" type="file" id="MYPdf">

<cfinput name="MYVfile" type="file" id="MYVfile">

</cfform>

Action Page:

<!--- set file uploading vars --->
<cfparam name="fileuploaded" type="boolean" default="false">
<cfparam name="uploadedfile" default="">
<cfset pathToFile = "c:\websites\215296Kh8\images\contentfile\">
<!--- --->
<cfif len(trim(form.MYFile))><!--- if a file has been selected --->
<!--- try uploading new file --->
<cftry>
<cffile Action="upload" filefield="MYFile" accept="image/gif,
image/jpg, image/jpeg, image/pjpeg"
destination="#pathToFile#" nameconflict="MAKEUNIQUE">
<cfset fileuploaded = true>
<cfset uploadedfile = cffile.serverfile>
<cfcatch type="any">
<!--- if upload did not suceed, reset file uploading vars --->
<cfset fileuploaded = false>
<cfset uploadedfile = "">
</cfcatch>
</cftry>
</cfif>

<!--- set file uploading vars --->
<cfparam name="PDFfileuploaded" type="boolean" default="false">
<cfparam name="PDFUploadedfile" default="">
<cfset pathToFile = "c:\websites\215296Kh8\images\contentfile\">
<!--- --->
<cfif len(trim(form.MYPdf))><!--- if a file has been selected --->
<!--- try uploading new file --->
<cftry>
<cffile Action="upload" filefield="MYPdf" accept="application/pdf, application/msword" destination="#pathToFile#" nameconflict="MAKEUNIQUE">
<cfset PDFfileuploaded = true>
<cfset PDFUploadedfile = cffile.serverfile>
<cfcatch type="any">
<!--- if upload did not suceed, reset file uploading vars --->
<cfset PDFfileuploaded = false>
<cfset PDFUploadedfile = "">
</cfcatch>
</cftry>
</cfif>

<!--- set file uploading vars --->
<cfparam name="VCFfileuploaded" type="boolean" default="false">
<cfparam name="VCFUploadedfile" default="">
<cfset pathToFile = "c:\websites\215296Kh8\images\contentfile\">
<!--- --->
<cfif len(trim(form.MYVfile))><!--- if a file has been selected --->
<!--- try uploading new file --->
<cftry>
<cffile Action="upload" filefield="MYVfile" accept="text/x-vcard, application/vcard (Macintosh only), text/anytext, text/directory, application/x-versit (Eudora Plug-in), text/x-versit (Eudora Plug-in), text/x-vcalendar" destination="#pathToFile#" nameconflict="MAKEUNIQUE">
<cfset VCFfileuploaded = true>
<cfset VCFUploadedfile = cffile.serverfile>
<cfcatch type="any">
<!--- if upload did not suceed, reset file uploading vars --->
<cfset VCFfileuploaded = false>
<cfset VCFUploadedfile = "">
</cfcatch>
</cftry>
</cfif>

<cfif form.id gt 0><!--- updating an existing record --->
<!--- if new file upload was successful and the feature has an file
associated with it - delete old file --->
<cfif fileuploaded is true AND len(trim(form.oldimage))>
<cfif FileExists(pathToFile & form.oldimage)>
<cffile action="delete" file="#pathToFile & form.oldimage#">
</cfif>
</cfif>
<cfif PDFfileuploaded is true AND len(trim(form.oldPDF))>
<cfif FileExists(pathToFile & form.oldPDF)>
<cffile action="delete" file="#pathToFile & form.oldPDF#">
</cfif>
</cfif>
<cfif VCFfileuploaded is true AND len(trim(form.oldVCF))>
<cfif FileExists(pathToFile & form.oldVCF)>
<cffile action="delete" file="#pathToFile & form.oldVCF#">
</cfif>
</cfif>

<cfquery name="UpdateDetails" datasource="#APPLICATION.dataSource#">
UPDATE Projects
SET
<cfif fileuploaded is true>
Projects.MYFile=<cfqueryparam cfsqltype="cf_sql_varchar" value="#uploadedfile#">,
</cfif>
Projects.mainPhone=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.mainPhone#">,
<cfif PDFfileuploaded is true>
Projects.MYPdf=<cfqueryparam cfsqltype="cf_sql_varchar" value="#PDFfileuploaded#">,
</cfif>
Projects.mainEmail=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.mainEmail#">,
<cfif VCFfileuploaded is true>
Projects.MYVfile=<cfqueryparam cfsqltype="cf_sql_varchar" value="#VCFfileuploaded#">,
</cfif>
Projects.position=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.position#">,
Projects.Body=<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.PDSeditor#">,
Projects.CategoryID=<cfqueryparam value="#form.CategoryID#" cfsqlType="CF_SQL_INTEGER">
WHERE ProjectID = <cfqueryparam value="#form.ID#" cfsqlType="CF_SQL_INTEGER">
</cfquery>

<cflocation url="part-manager.cfm?ID=#Form.ID#" addtoken="no">

<cfelse>

<cfquery name="InsertDetails" datasource="#APPLICATION.dataSource#">
    INSERT INTO Projects
(MYFile, mainPhone, MYPdf, mainEmail, MYVfile, position, Body, CategoryID)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#uploadedfile#" null="#NOT fileuploaded#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#PDFUploadedfile#" null="#NOT PDFfileuploaded#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#VCFUploadedfile#" null="#NOT VCFfileuploaded#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.mainPhone#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.mainEmail#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.position#">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.PDSeditor#">,
<cfqueryparam value="#form.CategoryID#" cfsqlType="CF_SQL_INTEGER">)
</cfquery>
<cfquery name="qFetchID" datasource="#APPLICATION.dataSource#">
     SELECT id
     FROM Projects
     WHERE mainEmail =<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.mainEmail#">
</cfquery>
<cflocation url="part-manager.cfm?id=#qFetchID.id#" addtoken="no">
</cfif>

I'm sorry it's so much code.. I commented it out a little so you can see what I'm doing... It's just writting to the database improperly on both the update and insert.

Thank you.

TOPICS
Advanced techniques

Views

871

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2011 Jun 04, 2011

Copy link to clipboard

Copied

LATEST

You have this (LOOK AT THE BOLD LETTERS) :

<cfset PDFUploadedfile = cffile.serverfile>

.......

<cfif PDFfileuploaded is true>
Projects.MYPdf=<cfqueryparam cfsqltype="cf_sql_varchar" value="#PDFfileuploaded#">,
</cfif>

instead of

<cfif PDFfileuploaded is true>
Projects.MYPdf=<cfqueryparam cfsqltype="cf_sql_varchar" value="#PDFUploadedfile#">,
</cfif>

maybe try to use less confusing names like :

PDF_UploadedfileName

AND

PDF_FileUploaded_YN

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation