-1

This is my code to get the file from user and attach it to the mail.

<cfset destination = expandPath('Uploads/')>
<cffile action='upload' filefield='file_upload' destination='#destination#'       result='upload' >
<cfmail to="id" from="id" subject="test">
<cfmailparam file="destination">
</cfmail>

When I run this I get an error, The resource destination was not found. Could you please help?

esyana
  • 57
  • 9
  • `destination` in `` is just a string, not a CF variable. It would need to be ``, although that would just be the path to your Uploads directory. You probably want to use `` or something similar. – duncan Nov 23 '15 at 10:39
  • Thanks a lot. It helped. Could you please help me with one more thing? I have written the code for mail trigger such that it will be called when the form is submitted. I need to trigger the mail only after the file has been uploaded completely. Form will be submitted even when the file upload is not completed. (file will be uploaded at the back) Is that right? – esyana Nov 23 '15 at 11:05
  • For the code you posted, I believe the mail tag will execute after the file upload is complete. It's easy enough to test though. Upload a large file and email it to yourself. – Dan Bracuk Nov 23 '15 at 13:00
  • Yeah, I did that Its triggering mail after the upload is completed; but I don't understand how, Should not it trigger mail once we click submit and the upload should be happening on back? – esyana Nov 23 '15 at 13:07
  • Unless you do something to prevent it, programming code executes in the order it appears. In this case, the mail tag starts when the file tag finishes. – Dan Bracuk Nov 23 '15 at 15:32

1 Answers1

2

You can do some thing like this

 <cfset destination = expandPath('Uploads/')>
<cffile action='upload' filefield='file_upload' destination='#destination#'       result='upload' >
<cfmail to="#id#" from="#id#" subject="test">
<cfmailparam file="#destination#/#upload.serverFile#" >
</cfmail>

For more information you can see cfmailparan and cffile action="upload"

Keshav jha
  • 1,356
  • 8
  • 22
  • Thank You.Can I use a variable defined in a cfm file in another cfm file? For eg: I have defined destination here and I want to use it in another cfm as well. Is that possible? – esyana Nov 23 '15 at 11:11
  • depends on what you want to do, if you are processign another cfm in the same request then you can included it in first cfm using cfinclude or you can call another cfm as custom tag and send variable value using custom tag attribute. but if there is new request for 2nd cfm then you have to use one of the persistent scope to achieve this. – Keshav jha Nov 23 '15 at 11:17
  • like calling a method from another method by passing arguments? – esyana Nov 23 '15 at 13:08