Showing posts with label cffile. Show all posts
Showing posts with label cffile. Show all posts

Sunday, October 03, 2010

Simple Java to make sure a directory exists before doing a cffile upload

Simple Java to make sure that a directory exists before doing a cffile upload:

<cfset CreateObject("java", "java.io.File").init("C:\Inetpub\wwwroot\myNewDirectory\images").mkdirs() />

So, for example, you might do something like this:

<cfset CreateObject("java", java.io.File").init("c:\uploads\#dateformat(now(), 'yyyymmdd')#") />

You can just do the above before every upload.&nbsp; The first time it will create the directory, and every time after that it will just do nothing.

Thanks to cfgears for reminding me how to do this:

http://www.cfgears.com/index.cfm/2009/5/19/Tapping-in-to-ColdFusions-underlying-Java-capabilities

Saturday, August 29, 2009

Getting cffile to work in a cfwindow

Figured out how to do a file upload in a cfwindow using cfform. If you try to receive a file upload in a cfwindow, regardless of the enctype specified in the cfform it will incorrectly receive the form as of type "application/x-www-form-urlencoded", instead of the more-better "multipart/form-data. My guess is that this has something to do with the ajax used to submit the form. This error happens even if the originating form is in the cfwindow.

Easy work around? Embed an iframe in the cfwindow, put your form in the iframe, and have the form submit within the iframe using a simple submit button (rather than using ColdFusion.navigate). If you submit the form using a submit button in an iframe, the form's enctype will submit properly, and ColdFusion will correctly receive your file and pass it onto cffile.

This technique will also work with putting a cfpresentation tag in a cfwindow.