?
Solved

cffile action=delete

Posted on 2003-02-21
10
Medium Priority
?
408 Views
Last Modified: 2013-12-24
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
Comment
Question by:texbala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:cdillon
ID: 7994809
Do you know what the error is that you are catching?
0
 

Author Comment

by:texbala
ID: 7995369
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
 
LVL 17

Expert Comment

by:anandkp
ID: 7997559
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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8002849
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
 

Author Comment

by:texbala
ID: 8005109
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
 
LVL 17

Expert Comment

by:anandkp
ID: 8006247
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
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8008233
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
 

Author Comment

by:texbala
ID: 8009108
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
 
LVL 9

Accepted Solution

by:
HamdyHassan earned 400 total points
ID: 8010475
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
 

Author Comment

by:texbala
ID: 8010706
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question