Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

cffile action=delete

I have a form with name, email fields and a file field for resume collection - resume has to be emailed to an address.I am not able to delete the file that I uploaded seconds ago. Pls. help!! - It attaches the file along with the e-mail, but doesn't delete the file and goes to catch block.

===============
<cftry>
<cfif FORM.filename neq "">
       <cffile
                  action="upload"
               filefield="filename"
               destination="C:\webroot_development\alumni_center\resume\"
               nameconflict="Makeunique"
               accept="application/msword, application/pdf, text/plain">
       <cfset NewFile = "C:\webroot_development\alumni_center\resume\#file.serverfile#">
</cfif>
<cfmail to="mail@email.com"
          from="mail@email.com"
          subject="subject"
            > 
Name =#name#
E-mail = #email#
          <cfif IsDefined ("NewFile")>
               <cfmailparam file="#NewFile#">
          </cfif>

</cfmail>

 <cfif IsDefined ("NewFile")>
  <cfif FileExists("#NewFile#")>
    <cffile action="delete" file="C:\resume\#NewFile#">
  <cfelse>
    THE FILE DID NOT EXISTS
  </cfif>
</cfif>

<!---
<cfif IsDefined ("NewFile")>

     <cffile action="delete" file="C:\resume\">
</cfif> --->


<cfset blnIsSuccess = "TRUE">

<cfcatch type="any">
<cfset blnIsSuccess = "FALSE">
</cfcatch>
</cftry>



<cfif blnIsSuccess>
     Email Sent
            <cfelse>
     Please upload a valid file. Valid file includes: Word document, PDF or text file<br>Please try again.
</cfif>

===============
0
texbala
Asked:
texbala
  • 4
  • 3
  • 2
  • +1
1 Solution
 
cdillonCommented:
Do you know what the error is that you are catching?
0
 
texbalaAuthor Commented:
In the mean time... i was changing some parts of the code.. see below!!

The form page has name, email fields and one filefield tag (named 'filename').

In the script page (where the form is sumbitted)
============

<meta http-equiv="refresh" content="5; URL=http://lcs_delete.cfm">

<cfif FORM.filename neq "">
 <cfset client.filename='#form.filename#'>
 
 <cffile
 action="upload"
 filefield="filename"
 destination="C:\resume\"
 nameconflict="Makeunique"
 accept="application/msword, application/pdf,
 text/plain">
 
 
 </cfif>
 
 <cfmail to="mail@e..."
 from="mail@e..."
 subject="subject">
 Name =#name#
 E-mail = #email#
 <cfif IsDefined ("client.filename")>
 <cfmailparam file="#client.filename#">
 </cfif>
 
 </cfmail>
 ========================
 code on lcs_delete.cfm page:
 
 ========================
 <cffile action="delete" file= "C:\resume\#client.filename#">
 <cfset client.filename="">
 ========================


I get an error saying "Element FILENAME is undefined in CLIENT" in the delete page... - the file is also not uploaded.

thnx!!
0
 
anandkpCommented:
i suppose ur trying to attach the file that is uploaded to teh server right

in that case - it shld be server.filename

u can only delete things from the server - so the path "C:\resume\#client.filename#"> shld correspond to the file on the server & not on client machine

let me know

K'Rgds
Anand
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
HamdyHassanCommented:
Hello,

1. you don't need client varaibles.
2. check permission on c:\resume
3. avoid filename as field name, try something like ResumeFileName



Now try the following


<cfset filePath="c:\resume">

<cfif #form.ResumeFileName# is not "">

  <CFFILE ACTION="upload" FILEFIELD="form.ResumeFileName" DESTINATION="#filePath#" NAMECONFLICT="overwrite">

  <CFIF #File.FileWasSaved# Is "Yes">
     Upload is done
  <else>
     Proble.........
  </cfif>

</cfif>



let me know if this work, then we will build other code on that

Hamdy
0
 
texbalaAuthor Commented:
Hamdy...
Yes.. your code works now!!
I need to mail to a e-mail (and attach the resume as attachment) and then delete the uploaded file after mailing.

Anand: Yes.. I tried that.. it didn't work out properly..
==============
<cfif FORM.filename neq "">
     
       <cffile
                  action="upload"
               filefield="filename"
               destination="C:\resume\"
               nameconflict="Makeunique"
               accept="application/msword, application/pdf, text/plain">
       <cfset NewFile = "C:\resume\#file.serverfile#">
       
       
</cfif>

<cfmail to="email@mail.com"
          from="email@mail.com"
          subject="subject">
Name =#name#
E-mail = #email#
               <!--- <cfif IsDefined ("NewFile")>
                    <cfmailparam file="#NewFile#">
               </cfif> --->

</cfmail>
=============================


Thnx for ur responses!!
0
 
anandkpCommented:
oops

i wonder - how my suggestion didnt work for u !

i assumed u were pretty through with using CFFile - thats y i just gave a breif outline on it.

nevermind ... :)

cheers
Anand
0
 
HamdyHassanCommented:
I am glad it's working for you.

Now next step is to email the attached resume, try the following


<cfset filePath="c:\resume">

<cfif #form.ResumeFileName# is not "">

 <CFFILE ACTION="upload" FILEFIELD="form.ResumeFileName" DESTINATION="#filePath#" NAMECONFLICT="overwrite">

 <CFIF #File.FileWasSaved# Is "Yes">
    Upload is done
   <CFSET varFileName='#FILE.ServerFile#'>
 <else>
    Proble.........
 </cfif>

  <cfif IsDefined('varFileName')>
     <cfmail to="#form.email#" from="email@mail.com" subject="Hello" type="html" mimeattach="#filePath##varFileName#">
              Email with attachment.
     </cfmail>
  <cfelse>
     <cfmail to="#form.email#" from="email@mail.com" subject="Welcome" type="html">
              Email without attachment.
     </cfmail>
  </cfif>

</cfif>




0
 
texbalaAuthor Commented:
Hamdy - thnx it is working...

what shld be done to delte the file... I tried to delete using

<cffile action="delete" file="#filePath##varFileName#">

I guess, the file is not uploading (and hence not e-mailing).
0
 
HamdyHassanCommented:
To delete...........

<cfif IsDefined('varFileName')>

<CFFILE ACTION="delete" file="#filePath##varFileName#" SOURCE="#filePath##varFileName#">

</cfif>


What do you mean "it's working" ? and at the same time you said "I guess, the file is not uploading (and hence not e-mailing)."


You need to make sure the file uploading ok, emailed ok, then we will delete it

Also I found a post with a good example close to what do you want


<cfset filePath="d:\">

    <cfif #form.myDoc# is not "">
        <CFFILE ACTION="upload" FILEFIELD="form.myDoc" DESTINATION="#filePath#" NAMECONFLICT="overwrite">
        <CFIF #File.FileWasSaved# Is "Yes">
             <cfif (#right(FILE.ServerFile,4)# is not ".doc")>
                  <CFFILE ACTION="delete" file="#imgPath##FILE.ServerFile#" SOURCE="#imgPath##FILE.ServerFile#">
                  <cflocation url="http://yahoo.com">
             </cfif>
         <!--- Validate the file name --->
              <CFIF #ReReplace(FILE.ServerFile,"['""## !@$%^&*()+={}|\/?<>,]","_","ALL")# Is NOT "#FILE.ServerFile#">
                  <CFSET newFName='#ReReplace(FILE.ServerFile,"['""## !@$%^&*()+={}|\/?<>,]","_","ALL")#'>
                  <CFFILE ACTION="Rename" SOURCE="#filePath##FILE.ServerFile#" DESTINATION="#filePath##newFName#">
             <cfelse>
                   <CFSET newFName='#FILE.ServerFile#'>
             </CFIF>
        </CFIF>
   </cfif>

at http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20442413.html

0
 
texbalaAuthor Commented:
I used another method to solve the problem (cfdirectory to delete all the files before uploading...)

PS: I meant "it is working" (for the code that u wrote for uploading the file - u didn't write the code for deleting the file). Thnx for your help!! :)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now