Need help with ColdFusion

Thraxen

Diamond Member
Dec 3, 2001
4,683
1
81
OK, I'm working on an online job application form. Once the form is completed a copy of the form is e-mailed to the appropriate address. The form also includes the ability for the user to browse for a file (resume) on their local machine and have it uploaded and attached to the e-mail... that's the goal anyway.

I've got the form built and the e-mail function works, but I can't get the file to attach to the e-mail. The files are being uploaded... I can find them in the upload directory.

This is the file code for allowing the user to choose the file to upload:

<input type="file" name="resume" value="" size="45">

This is the code before the CFMAIL tag relating to the attachment:

<cfset attachment_directory = "/example_com/www/new/uploads">

<cfif form.resume neq "">
<CF_FileUpload userid="xxxxxx" password="xxxxx" action="upload" filefield="resume" destination="#attachment_directory#" nameconflict="Makeunique">
<cfset attachment_resume = "#attachment_directory#/#cffile.serverfile#">
</cfif>
CF_FileUpload is a secure form of CFFILE... CFFILE has been disabled by our host.

This is the code within the CFMAIL tags that is being used to attach the file:
<cfsilent>
<cfif form.resume neq "">
<cfmailparam file="#attachment_resume#">
</cfif>
</cfsilent>

This is the error I get when I attempt to include an attachment:
Error Diagnostic Information
Unable to attach file.

Cannot attach '/example_com/www/new/uploads/example.doc' to the mail message. The file does not exist.

That path is correct (it works for uploading the file) and the file does indeed exist. I can FTP out to the site after attempting to submit the form and find it in the uploads folder.

I also tried using "mimeattach=" to attach the files, but that results in the same error. Same with using the absolute path instead of the relative path for the location of the file... the same "File not found" error results.

So I'm stumped. Any ideas?

So what's going on here? Why


 

Thraxen

Diamond Member
Dec 3, 2001
4,683
1
81
That's what I meant by "absolute path" near the end of my comments. I was able to find the full path using the getCurrentTemplatePath() command. I inserted that into my code and still got the same error.
 

Furor

Golden Member
Mar 31, 2001
1,895
0
0
Two things I can think of here...

By default (in Windows, probably the same in linux) Coldfusion only has local system access, so doing any kind of IO process on another drive will throw an error and requires changing the service to log in as a higher level account.

The other thing is mappings - if your Coldfusion server has a mapping for '/' - it usually causes problems with file operations. On the other hand, if you have administrator access, you can try to create a mapping to the folder you want and see if that helps.

Also - I noticed you aren't doing any file checking...with all my upload forms, I create a list of valid extensions (.mdb, .xls, .txt, .doc, etc) and check against the upload file - otherwise people receiving the email are likely to get virus' and crap.

Last..if someone uploads a blank file, coldfusion will throw an error so you'll want to catch that.
 

Thraxen

Diamond Member
Dec 3, 2001
4,683
1
81
Originally posted by: Furor
Two things I can think of here...

By default (in Windows, probably the same in linux) Coldfusion only has local system access, so doing any kind of IO process on another drive will throw an error and requires changing the service to log in as a higher level account.

The other thing is mappings - if your Coldfusion server has a mapping for '/' - it usually causes problems with file operations. On the other hand, if you have administrator access, you can try to create a mapping to the folder you want and see if that helps.

Also - I noticed you aren't doing any file checking...with all my upload forms, I create a list of valid extensions (.mdb, .xls, .txt, .doc, etc) and check against the upload file - otherwise people receiving the email are likely to get virus' and crap.

Last..if someone uploads a blank file, coldfusion will throw an error so you'll want to catch that.

About your first two comments... could those still apply even if the upload does work? Because I can upload a file just fine.

Just as a test I changed the code on the e-mail form so that it would attempt to attach a file already out on the server rather than attempting to attach the file being uploaded from the form and I still got the same "file not found" error.

Also, I do plan on implementing some file and form validation, I just wanted to get the form working properly first.


[edit] Never mind... I was finally able to get it working. I had to call the file using this:

<cfmailparam file="#cffile.serverDirectory#\#cffile.serverfile#">

Attempting to define the upload path and then using that variable to call the file wouldn't work for some reason.