views:

43

answers:

4

I'm having trouble using cffile right before I create a directory. I am using the cffileupload tag and my url attribute is a page that has the following code. Basically the code below creates a new directory and uploads all the images to that directory. However, it fails on the 2nd upload and i get a 500 error in the cffileupload flash object. However, if I hardcode the directory path, they all upload fine. Anyone know why I am having this problem?

<!--- User will upload all the images to a temp directory based on date and time --->
<cfset uploadFolderPath = "C:\ColdFusion9\wwwroot\MyApplication\uploads\" />
<cfset date=DateFormat(Now(),'mm-dd-yyyy_') />
<cfset time=TimeFormat(Now(),'hh-mm-ss') />
<cfset newFolderName = "upload_" & date & time />
<cfset newFolder = uploadFolderPath & newFolderName />
<cfdirectory action = "create" directory="#newFolder#" />

<cffile action="uploadall" destination="#newFolder#" nameconflict="makeunique" />
A: 

You should first check if the directory exists before creating it right, otherwise it will error out?

raulriera
A: 

Using the flash based cffileupload is probably causing you to lose out on the valuable debug message you should be seeing. You could also hook up a proxy like Fiddler to see what ColdFusion is actually receiving/sending. Posting the relevant exception information will be helpful.

As stated by raulriera, your problem probably lies in the cfdirectory call to create the new folder, it will error out if the directory already exists.

Goyuix
+1  A: 

ok so I found out that the url path in cffileupload is called for each file being uploaded, so it was failing because the processing script was was trying to create an already existing directory from the previous file uploaded (which occurred during the same second). checking to see if the directory exists before creating it solved my problem.

phpguy
+1  A: 

Use following coding. I've added "DirectoryExists" function in your existing coding.

<cfset uploadFolderPath = GetDirectoryFromPath(GetCurrentTemplatePath()) /> <cfset date =DateFormat(Now(),"mm-dd-yyyy") /> <cfset time = TimeFormat(Now(),"hh-mm-ss") /> <cfset newFolderName = "upload_" & date & time /> <cfset newFolder = uploadFolderPath & newFolderName />

<cfif NOT DirectoryExists(currentDirectory)> <cfdirectory action = "create" directory="#newFolder#" /> </cfif>

<cffile action="uploadall" destination="#newFolder#" nameconflict="makeunique" />

ppshein