About two months ago I was asked by a client to help her understand file uploads and ColdFusion. I wrote her up a document and then asked if I could blog it. She graciously agreed (I've been lucky in that regard - I've hard multiple clients pay me for work and then ask that I share it with the world. Clients rule!) and I've pasted the document below. It is very basic - but figured it may be useful to share. I've also included a PDF export.
Working with File Uploads
Adding a file upload feature to your web site is relatively simple, but there are some basic questions you should answer first before writing code. The first question you want to ask is what types of files are allowed. For example - if your intent is to allow someone to upload a resume, most likely you want to allow for Word docs, PDFs, and TXT files. If you site is letting someone upload a picture, than you want to restrict the types to GIF, JPG and PNG. You may also want to go further than just checking the file extension. You may want to use a third party tool like Alagad Image CFC or ColdFusion 8's built in image support to not only confirm that the file is indeed an image, but also ensure that the dimensions aren't too big.
The next consideration to make is where these files will be stored. You have a few concerns here:
- The first concern is a basic one - disk space. If you are letting people upload images, it is possible that your hard drive could get filled. With the sizes of today's hard drives and with most of us not getting a lot of traffic (comparatively), you may never even get close to filling your hard drive. The question is though - how would you know? There is no built in way within ColdFusion to determine the amount of free space available on a drive (although CFLib has two different Windows only options, AvailableSpace and FreeSpace). You could however simply generate a report of the total size of one folder. This can be done using a recursive cfdirectory and query of query:
<cfdirectory directory="#expandPath('.')#" recurse="true" action="list" name="allfiles">
<cfquery name="getSize" dbtype="query">
select sum(size) as total
from allfiles
</cfquery>
<cfoutput>Total size in bytes is: #getSize.total#</cfoutput>
This could be done daily and sent via email using a scheduled task. Or it could be displayed in the your web site's administration section. Either way - you want to at least have a good idea of how much space is being used and how much space is available. If your site gets a lot of traffic and could possibly have quite a few uploads, you may need to look into using another server just for the storage and serving of the media files.
- The next question is how you will handle files with the same name. ColdFusion provides a simple way to handle that when uploading. It has a makeUnique feature that will automatically detect a file name conflict and give your upload a new name, but you need to be sure you use this (if it makes sense) and that you recognize the file changed. If you store the file name in the database (a good idea so that you can associate uploads with a user) you may want to consider storing both the original file and the file name ColdFusion used. This lets the user see his original (and recognized) file name while keeping a link to the real file name on the system.
So hopefully now at this point you have an idea of what you want to do with the files - now lets look at the actual code. First and foremost you will need a form. The only way a browser can upload a file is via a form that uses a input tag with type of file. There is no other way (outside of a Java or Flash file) that you can let users upload a file. So a very, very simple upload form could look like so:
<form action="test.cfm" method="post">
Select a file: <input type="file" name="uploadfile">
<input type="submit" value="Upload File">
</form>
While this looks ok, there is one problem. When using a file upload, you have to specify a special type of form. You won't see a problem until you actually try to upload the file with CFFILE. The error you will see is:
The cffile action="upload" requires forms to use enctype="multipart/form-data"
Well you have to hand it to ColdFusion. It told you exactly what was wrong, and don't feel too bad - I forget this all the time. All you need to do is add the specified enctype attribute to your form tag, like so:
<form action="test.cfm" method="post" enctype="multipart/form-data">
Select a file: <input type="file" name="uploadfile">
<input type="submit" value="Upload File">
</form>
So this fixes the form - now lets move on to the processing. As hinted at above - the CFFILE tag will actually do the upload. To be clear - the web server handles the file upload, but the CFFILE tag is what actually lets your process the upload. It gives you a way to say, "Take the user's file and put it here." Let's look at a simple example:
<cfif structKeyExists(form, "uploadfile")>
<cfset destination = expandPath("./files")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload" filefield="uploadfile" destination="#destination#" nameConflict="makeUnique" result="upload">
<cfdump var="#upload#">
</cfif>
This code block will only run when the form field, uploadfile, exists. The first 4 lines simply check to see if a subdirectory named files exists. Normally you would probably use a folder that already exists, but this is a handy way to set it up for me. (I'm a lazy SOB.) The real critical line here is the CFFILE tag. Let's look at each attribute. The first attribute, action, specifies that we are doing an upload. (Duh.) The next attribute is interesting. You tell ColdFusion the name of the form field that contains the file. Notice I didn't use #s or form. I just used the form field name. (And yes - you can have more than one file upload in a form.) Next I specify a destination folder, using the variable I created earlier.
Now pay special attention to the nameConflict attribute. As I mentioned above, if you have multiple users uploading files (or even just one user uploading multiple files), the chance that two files could have the same name will grow. You have 4 options for this attribute:
- Error: If error is used and a file name conflicts, an error will be thrown.
- Skip: The file will simply not be saved.
- Overwrite: This will overwrite the existing file.
- MakeUnique: This will create a new file name.
The last attribute, result, simply specifies that the result of the action should be stored in a structure named upload. In ColdFusion 6 and earlier, this variable was always named CFFILE. So what gets stored in the structure? Quite a bit actually. Here are the keys you can expect to be returned:
- attemptedserverfile: This is the file name ColdFusion tries to use for the file it will save. As far as I can see, this seems to match with the name of file on your system. Most likely the name would only change if you uploaded a file with a name that was valid on your system and not valid on ColdFusion's host operating system.
- clientDirectory: The directory of the file that user upload.
- clientFile: The file the user uploaded.
- clientFileExt: The extension of the file the user upload.
- clientFileName: This is a weird one. This value is the filename of the file uploaded - minus the extension. I get confused by this all the time.
- contentType and contentSubType: The MIME content type and subtype of the file uploaded. This can be used to restrict uploads to certain types of files.
- dateLastAccessed: The docs say this is the date and time the file was last accessed. When I look at this result though I see only the date.
- fileExisted: This is a boolean that tells you if a file with the same name existed when you ran the CFFILE tag. If you use nameConflict="skip", this would be one way to determine if a skip action occured.
- fileSize: The size of the uploaded file.
- fileWasAppended: A boolean that tells you if the file was appended to an existing file. Since "append" isn't even a valid option, I'm not quite sure why this exists.
- fileWasOverwritten: A boolean that tells you if the file was overwritten. This would only work if nameConflict was set to overwrite. Otherwise it will always be false.
- fileWasRenamed: A boolean that tells you if the file was renamed. This would only work if nameConflict was set to makeUnique. Otherwise it will always be false.
- fileWasSaved: A boolean that tells you if the file operation completed. This would only be false if skip was used for nameConflict.
- oldFileSize: If a file upload overwrites another file, this will tell you the size of the old file. Not quite sure how useful this is.
- serverDirectory: The directory where the file was saved.
- serverFile: The filename of the file. Useful when makeUnique is used.
- serverFileExt: The extension of the uploaded file.
- serverFileName: Like clientFileName, this is the filename of the file minus the extension.
- timeCreated and timeLastModified: The create and lastmodified values for the uploaded file. Unlike dateLastAccessed, this seems to be a complete date and time stamp.
Ok, so a lot was covered there. Basically the structure gives you everything you need to handle the post-upload process. Need to store the uploaded file name and remember the original file name? The data is there. Want to use ColdFusion 8's image functions to ensure the image is the right size? The data is there. (And if you want an example of that - download the sample code from my blog post on CFIMAGE: Recording from ColdFusion 8 Image Presentation.)
Security Concerns
Before allowing a user to upload a file, think long and hard about what this means for security. First off - will you be storing the files under web root? If so - it means anyone can then link to the file - whether or not you intended them to do so. You may have a nice, family oriented web site, but if you let folks upload images, there is a good chance someone could upload porn, and then link to it from other sites. Most likely you do not want to store any uploaded file under the web root. You also want to make it easy to review uploaded files. You could fire off an email everytime someone uploads a file. You could also build an admin interface that lets you browse uploaded files and double check them for appropriateness.
Another concern would be allowing users to upload code. Imagine if you let users upload anything and they decided to upload a CFM file? The user would then be able to execute any code against your server they want if the file was stored under web root. You definitely want to prevent this by ensuring that the file isn't under web root.
One last tip you may want to consider. If you do want to limit what types of files can be uploaded, consider the accept attribute. This attribute takes a list of MIME types you want to allow. The docs demonstrate allowing Word and JPG files like so: accept = "image/jpg,application/msword". Two small issues with this. First - you need to know the MIME types. Since my brain only has room for useless Star Wars trivia, I usually have to look this up. (Here is a good URL for a list of MIME types: http://www.w3schools.com/media/media_mimeref.asp) The second thing to consider is that the accept attribute only checks the extension. A user could write a text file, save it with a .jpg extension, and the accept attribute would gladly let it pass. Note that ColdFusion 8 provides native functions to see if a file is a PDF or image. These can be used along with accept to really ensure a file is proper.
Archived Comments
What are you feelings on the naming of files? Ex.
This File IS Windows Valid.doc
How does CFFILE handle that kind of nonsense?
Side Note: I use the storage method you mentioned where you store the original filename and then CF version of the saved file. I've even gone far enough to use the UUID Primary Key of the Document record as the name of the File that is uploaded. Thoughts, Feelings, Gold Leader Standing By.
Some web hosts limit the size you can upload as well. Hostmysite now limits it to 8MB or so. Usually not a big deal, but something for people to consider in the planning stages if they don't have full control over their server.
Something else I have seen is to upload the files first to CF's temp folder, do additional security and type checks, fize size checks, etc. then move it to the final destination folder if all checks out.
Nick - that filename is valid on all supported platforms, so I'm not quite sure what you are asking.
Let me flip the question then. Are there filenames that are Valid across OS's but would cause CF to explode.
Ex. #4334.pdf
How would that filename cause CF to explode? CF doesn't care if a pound is in there. I mean shoot- consider cfquery. If you return a query with a # in the data, does CF care? No. It only cares when you _hard_ code something in, like so:
<cfset nicklikesparis = "Paris is ##1">
There I have to escape it. But if the value is already stored, like in a query, result of cfdirectory, etc, it doesn't matter.
Well, in my agency managment system users are allowed to upload files, especially in the homeowners department where we have to have pictures of all our insured properties. To keep it secured all filenames are stored as UUID's.
All images are automatically resized to make sure file size isn't huge.
I have been wanting to rewrite my old image processing code using CF8's extensions rather than using second party apps, as I am currently doing.
This article did bring up some points I didn't initially take into consideration such as is the image file an actual image? This is something I probably need to look at.
You should upload this tutorial onto the <a href="http://learncf.com/" target="_blank">learnCF.com</a> website.
A bit OT but if you are specifying the accept attribute for jpeg's remember to add image/pjpeg to allow IE to upload jpegs. Credit here...
http://rip747.wordpress.com...
As usual, great information Raymond. One question I have is how to manipulate the file name before you save the file. For instance, I need to make sure all filenames are lowercase when uploading files to my server. I have been unable to figure out how to access the $_FILES array in order to change the name (I'm also writing a bunch of PHP so I tend to confuse the two). I suppose I could use CFFILE to rewrite the names, but that seems like extra, unnecessary work if I can get it right the first time. Thanks.
Well, you can't rename a file on the client. You can easily rename the file after it is uploaded. You would just use cffile/rename.
That's what I ended up doing. Works fine. Hopefully it will scale as the upload volume increases. Thanks.
Great as always. Is there a chance to CFSET a form field before using cffile-upload? Any chance to put the file in the request?
I won't do that usually, but it would help me with a current project. I then could use very old code to upload a file without touching the whole system or creating (better) new code - but it must happen without a browser/client request.
Any clues?
You can't set a file to upload server side. The browser restricts that for security reasons.
So sorry, I don't want to use javascript or a browser because I can't use a separate (client) request.
What I wanted is to CFSET a value in CF and then using CFFILE:
<cfset form.uploadfile = ...>
<cffile action="UPLOAD" filefield="uploadfile" ...>
Read this blog entry by Charlie Arehart:
http://carehart.org/blog/cl...
Maybe I have not only to CFSET the formfield but also to copy the upload file into CF's temp directory from where CFFILE-upload can pull it.
My problem is that there is a big chunk of old code handling a file upload and doing a lot more to save the file to the system where it is managed. I don't want to write the whole stuff by myself (and forget doing something important) to import 1000 files. It will be much more simple and save to let the existing code doing that, but it uses a CFFILE-upload. All I have to do is to set the formfield name.
It should be only a trick if you can't change the whole existing code. You know how complex this old stuff can be.
Here is the code I used, see below.
You see
a) where file is (so you can copy yours to this location)
b) what information is stored in the form field (so you can set it to name name of the the temp file)
But I can't see where the original file name has gone. If I can't set that value CFFILE-upload can't work properly. Maybe there is something in the multipart form header?
Any help will be much appreciated.
Code of test.cfm :
<form action="test.cfm" method="post" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="submit">
</form>
<cfdump var="#form#">
<cfdirectory action="LIST" directory="#gettempdirectory()#" name="qDir">
<cfdump var="#qDir#">
<cfflush>
<cfloop query="qDir">
<cffile action="READ" file="#gettempdirectory()##qDir.name#" variable="filecontent">
<cfdump var="#filecontent#">
</cfloop>
@Michael - I don't think I'm getting you. You don't want a client request? Then how do you plan on uploading a file from the client to your server? You _can't_, repeat, cannot, do this automatically. The user must select a file. Otherwise web sites would be stealing files from users left and right.
As to your code - why don't you use the cffile tag as specified in this blog entry? That will give you stuff like the original file name.
I truly do not think I'm getting you here.
Thanks for your patience Raymond. I'll try to explain:
I have to use an existing custom tag (with <cffile action="UPLOAD" filefield="myfile" ...> somewhere inside) to import 1000 new files.
What can I do? I see 2 possible solutions:
1.) Use our applications standard upload form, filling in all the data, select the file and press submit.
Takes a few hours but would work (and next year again with 10000 files ...).
2.) Other solution!!!
I don't want to choose solution 1 and save me a few hours work. What's with solution 2? Is there any "other solution" possible here?
The only other solution as far as I can see is to set the form parameters programmatically and call the custom tag.
Lets try it. First of, what form parameters do I need?
I created the following form.cfm/test.cfm to see what is sent to the server by a file upload request.
Call test.cfm in the browser, fill in the form and press submit to see the form dump.
-form.cfm
<form action="test.cfm" method="post" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="submit">
</form>
/form.cfm
-test.cfm:
<cfdump var="#form#">
<cffile action="UPLOAD" filefield="myfile" destination="d:\temp\upload\">
/test.cfm
This works perfectly. There is a string called "form.myfile" in the dump pointing to the cf temp directory:
"D:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neoXXX.tmp"
and the file is physically moved to d:\temp\upload\ by the cffile tag.
Perfect? Hm... Here lies a problem. I can't see the original file name in the form struct. But cffile knows it and renames neoXXX.tmp after moving it. Where is it?
Anyway! I can see how the form parameters are set and now I can create form variables by myself before calling cffile. That is what counts. Forget about the original name.
(Maybe CF mustn't rename the file after moving it from the temp directory, then everything is fine.
So let's decide that the missing original name is maybe a problem - and if: then solve it later.)
From the dump in test.cfm I know that I must set form.myfile to a path/file in the temp directory.
Later I copy all 1000 files, but for testing I copied only "WINZIP.TXT" manually into the cf temp directory and then called import.cfm in the browser:
-import.cfm
<cfset form.myfile = "#gettempdirectory()#WINZIP.TXT">
<cffile action="UPLOAD" filefield="myfile" destination="d:\temp\upload\">
/import.cfm
import.cfm doesn't work. The cffile error is:
Message: Invalid content type: ''.
Detail: The cffile action="upload" requires forms to use enctype="multipart/form-data".
That says it all. I can't do it manually.
Is there really no other solution than 1.)?
I hope the problem is now clear. I know, I'm not an exceptionally gifted writer ;-)
Michael, you cannot automate the uploading of files from the client. Period. It's not possible unless you use some magical IE only ActiveX control. Browsers won't allow for automatic uploads like that.
The only option I can suggest is to move the 1k files to the CF server. Then you can run the import there by changing the code in the custom tag perhaps.
Thank you for your reply.
I don't want to upload anything from a client.
Forget everything that was said in the first 2 posts.
Try import.cfm in my 3rd post. This is what I want to do.
I can move the files to the CF server. I can do anything with the files what I want.
The only problem is: I can't change the custom tag and the whole application behind it.
It's not possible. If I could, I simply changed CFFILE-upload to CFFILE-copy and it works like a charm.
There is only one chance:
Writing some cf code to loop over the files, set variables into the form struct
and call the custom tag in the same request, making the custom tag (and cffile-upload)
believe that the call is coming from the form
This is what import.cfm tried to do. But it simply doesn't work.
All I need is pure CF code to set everything as a multipart form does.
Java - maybe? No html. No form. No javascript. One single request.
I see, there's no way to do that in Coldfusion.
Thank's anyway.
Ahhh. Well, it is unfortunate that you cannot change the custom tag. Can I ask why that is?
Nice article, but do you have any idea where ColdFusion hides the original filename, before the <CFFile action="upload">.
If we knew the original name we could do things like this...
Save.cfm
<!--- form.file contains the temporary upload location + filename --->
<cfset info = GetFileInfo(form.file) />
<cfif ListLast(originalFilenameGoesHere, '.') Eq 'txt' And info.size Lt 50000>
<cffile action="upload" filefield="form.file" destination="e:\docs" />
Upload is valid.
<cfelse>
Your upload is invalid.
</cfif>
This is what I'm trying to do with a validation component that I don't want moving files, just validating them.
I don't believe you can get that w/o first doing the upload. Technically the file is already uploaded and this action just "processes" the upload so you can handle it in CF.
I think you're right Ray, I've spent too long hunting for the filename now to know that even if I found it, I wouldn't want to use it as it's not documented and could change at any time.
It's a shame though, it'd be nice to avoid the extra overhead of creating a copying the file (cffile upload) just to find it has an invalid extension and then throw it away, especially if dealing with large uploads.
Fortunately for me I'm only dealing with smaller files. I'll just have to keep it on my CF9 wishlist though :)
Here is a way of geting the fiel name before you use CFFILE. Notice the onSubmit function when you submit the form, the clientFilePath will provide the local path of you file to upload.
<cfparam name="FORM.FileToUpload" default="">
<cfparam name="FORM.clientFilePath" default="">
<form action="#CGI.SCRIPT_NAME#?function=submit" method="post" enctype="multipart/form-data" onSubmit="this.clientFilePath.value = this.FileToUpload.value;">
<table border="0">
<tr>
<td class="newForm" nowrap="nowrap">Upload CV and Resume:</td>
<td><input name="FileToUpload" type="file" value="" class="newInput"></td>
</tr>
<tr>
<td align="right">Â </td>
<td align="left"><input name="Submit" type="submit" class="send" value="SEND"></td>
</tr>
</table>
</form>
Then on validate, strip the file name from the entire path and find the file extension before you use CFFILE, here is the code:
<cfif Trim(Form.FileToUpload) eq ''>
<cfset ValidateRecord = "#ValidateRecord#" & "<li>Please upload the resume.">
<cfelse>
<cfif CGI.CONTENT_LENGTH gt 2000000>
<cfset ValidateRecord = "#ValidateRecord#" & "<li>The file uploaded is bigger then 2 MB.">
<cfelse>
<cfset Form.clientFilePath = REReplaceNoCase(#Form.clientFilePath#, " ", "", "All")>
<cfset Form.FileName = REReplaceNoCase(#Form.clientFilePath#, "([A-Z]:\\)|\w+\\+", "", "All")>
<cfset Form.Ext = Right(Form.FileName, Len(Form.FileName) - Find('.',Form.FileName))>
<cfif Form.Ext neq 'doc' and Form.Ext neq 'pdf'>
<cfset ValidateRecord = "#ValidateRecord#" & "<li>Your resume document should be a word or pdf document.">
</cfif>
</cfif>
</cfif>
Let me know if you need the entire sample file.
Cheers,
Ilir
Hi Ilir,
I would like your complete validation file please. I'm having trouble making these snippets work properly. Can you email me? Many thanks.
@Ilir
Unfortunately, using cgi.content_length appears to take the entire set of form data into account. While this is alright if you have a relatively small form (other than the file being uploaded), it gets tough to say that a user should be able to upload anything 1MB or smaller using this method if you also have 100KB of other form data (text fields, selections, etc.)
In order to better gauge the size of the uploaded file (without actually performing a cffile upload on it), I came up with the following:
<!--- get file name (last item in list) --->
<cfloop from="1" to="#ListLen(form.uploadfile, "\")#" index="myPos">
<cfset Local.tempFileName = ListGetAt(form.uploadfile, myPos, "\") />
</cfloop>
<!--- get directory where we are storing it --->
<cfset Local.tempFileDir = Replace(form.uploadfile, Local.tempFileName, "") />
<!--- get directory list for file (including size) --->
<cfdirectory action="list" directory="#Local.tempFileDir#" name="myDir" filter="#Local.tempFileName#" />
<!--- Compare uploaded filesize to file size limit --->
<cfif myDir.size GT local.fileSizeLimit>
<!--- Handle the error --->
<cfelse>
<!--- Go ahead with the upload --->
</cfif>
I, too, am looking for the ever ellusive filename before the upload... Actually, I'm not even interested in ever doing a file upload, but I need a "file" input type box where the user can search for a file and then process the form. Is this possible?
I don't quite get what you are asking. You want the user to pick a file. But you don't want them to upload it. Are you saying you just want the user to pick a filename? If so, you can't really do that. The file will be uploaded.
I have the exact same concern as David Boyer a few posts up.
As we move into video land, file upload size is becoming a big issue, and having ColdFusion copy a file from the tmp directory seems like totally unnecessary overhead.
My application basically "hangs" while CFFILE moves a 1Gb+ file from temp to wherever I have specified, so after my progress bar says 100% due to the fact that the file is now 100% in the temp folder, the user is now sitting there waiting for CFFILE to respond (although he doesn't know it).
Anyone know a way to bypass the tmp upload scenario and just have the file go right where I want it to so no copy is required?
Could this be accomplished with another language like jsp or perl? My test server has all these languages installed. I am totally agnostic about how to get around this particular file upload issue. I am just looking for minimum overhead. Thanks.
JUST DELETE BAD FILES: Once it gets to the server, simply determine if you should immediately delete it. Use the attributes such as cffile.serverFileType, size, etc. to instantly turn around a DELETE cffile tag right after the cffile that UPLOADED it.
I was trying to limit .DAT files, but there is not a MIME code for this for the accept.
By not storing images in the webroot, are we talking about putting things above the webroot? If so, how are you calling the image into the HTML when serving it on a page?
You can serve images, and other things, from outside of the webroot by using CFCONTENT
I know I am late getting here... but I have to disagree with two comments.
1) You cannot automate the uploading of files on the client. That is not so. You can put each file field into it's own form. Then with ajax/javascript you can submit() those forms in order, one after the other.
2) You cannot get the file name before the file is uploaded. Well, you can. Again, with javascript. I made something called Fancy Upload which does that (and adds an icon). You can see it here (along with an upload progress indicator): http://www.webveteran.com/b...
@JG: 1) Are you saying your first sentence is incorrect? I'm not exactly sure what you mean. You cannot set the file of a file upload. Period. It's a security issue. If you could, I could set the file field to a sensitive file on your system (c:\boot.ini) and upload it w/o you knowing about it.
2) You are correct - you can get the filename once the user has selected the file.
That's not exactly what I mean. I probably wasn't clear, or I misunderstood the original comment. I meant you can automate the uploading.
Say have 5 file fields in rows. To the user it looks like one form. But it's really 5 forms stacked. (if you want to get dangerous you can have javascript create more on the fly with a cute button). The user select a file for each. Then at the end a button fires off a javascript that submits the first form (and hides it) - but submits it into a hidden iframe. The upload action page has a script at the end which tells the submitting page it's done, which in turn submits the next form in the line. Lather rinse repeat.
Ah ok, that makes sense then.
Ray, my file upload is in CFwindow and after uploading page left the Cfwindow and redirect to the action page.
How can I keep my upload on same page?
Thanks
File uploads with Ajax require special code. Google for file upload ajax for some examples.
I recently ran into a strange issue with cffile upload. I have a simple app which takes a .doc file that a user specifies and uses cffile upload to put it onto our linux box (where we are running CF6). I use the mode attribute to change the permissions on the file. Specifically, mode = 764.
Now, in some cases the files get uploaded with the correct permissions:
-rwxrw-r-- 1 wwwrun www 56832 2009-04-28 15:34 testdoc.doc
In other cases, using the same process, the mode = 764 is not applied to the uploaded file:
-rw-r--r-- 1 wwwrun www 70656 2009-04-28 15:56 testdoc2.doc
I assume this has to do with the file's security properties before ColdFusion ever touches it. Has anyone else run across this or have thoughts on how to work around it?
I'm fairly new to this ColdFusion world so if I'm asking a dumb question, well, that's why. :)
No idea - but CF6 is like 5 years old, isn't it? You might want to make sure it is patched up completely. Might want to also try CF8. ;)
Hi,
I used the line <cfif structKeyExists(form, "fileName")>
but I still get an error if a file is not selected.
"The form field "fileName" did not contain a file. "
It means no data was sent. Try
<cfif structKeyExists(form,"filename") and len(form.filename)>
Ray,
In reference to the first comments in this thread, how would CF handle a filename uploaded that was something like 'WelcomeToTheWeb2.0.xls'? This is a valid filename on Windows OS, but is CF able to successfully separate the name of the file and the file extension? Another example would be something like 'ThisIsAFile.txt.xls', which is a little different, since both are valid extensions, but may not be different in the eyes of CF.
"but is CF able to successfully separate the name of the file and the file extension"
certainly - the extension is just the last part.
Ditto for your next question - the extension will be the _last_ part of the file name.
Ray, I read both the article and the posts. But I have to offer an image upload solution in a multiple server environment with load balance. How to make sure the image uploaded by a client will be saved in only on place and not in every server each one is directed by de load balance mechanism?
You could use one machine in the cluster just for uploads. You could also use a NAS that all machines have access too. That's the only ideas that come to mind.
Hi everyone, I'm somewhat new to cf, as I've only been using it since cf8. and I've got a related question. I've got a form that encapsulates div tags which contain my form controls. I'm not exactly comfortable with this, but this is how my designer has done things thus far. for some reason my <cfinput> type=file name="userPic"> does not register with the form. I'm using coldfusion form and control tags for my form. I've made sure I'm using enctype="multipart/form-data" attribute in my form's opening tag.
I just don't see why all my other controls are registering except for this input of type file. Any suggestions?
Did you use cfdiv or div?
I'm using a form that allows a candidate to upload multiple documents. The directory that the person uploads to will follow the convention of username_nominationUploads so it will be unique to each person's username. The username is obtained from the email address in a form field called email.
In order to create the directory, I've included these lines of code:
<cfset destination = expandPath("/#left(email,8)#_nominationUploads")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload"
filefield="nominationLetter"
destination="#destination#"
nameConflict="makeUnique"
result="upload">
The directory is not created. Can anyone elaborate why it is not?
Thanks,
Adam
Did you add some logging? For example, maybe destination isn't what you think it is. Add a simple cflog that records the value. Then add a cflog for the result of directoryExists() on it. Also - an email address may contain @, and that may not be a valid directory name.
You said your code doesn't wor k- does it throw an error?
I have run into an issue with the uploading and writing of images. In certain instances, the file is uploaded and when the file is being written to the file directory, it throws an error "invalid file format null". I outputted the cffile structure immediately before the line that writes the file and everything in the structure seemed legit according to ColdFusion. However, the error persisted and I can find no log of it in the administrator. Has anyone experienced anything like this?
Hi all, has anyone had problems using file upload with Safari 4.0.5 I keep getting an error saying the form field did not contain a file. Weird as it works in all the other browsers. I tried posting my code but the page said I was spamming :0(
Is this Safari on the iPhone?
no just good old pc
Odd. I do know that on the iPhone, the field won't exist at all, so you want to ensure you do a isDefined (or structkeyexists) check first. Safari in general though doesn't prevent you from uploading files. That is a pretty critical failure. Can you verify it on other machines? Can you try off your network?
I'll do some more testing per your suggestions Ray and report back.
I've ran into that a lot. So this is what I do on upload pages:
<cfif isdefined("form.nominationLetter") and form.nominationLetter neq ''>
Also are you sure your FORM tag has enctype="multipart/form-data" ?
We have tried everything over the years to get reliable file uploads using cf6, then cf7, then cf8 and now cf9. All hoping and praying finally for reliable robust file uploads and yet it still seems a bridge too far. Is anyone actually using cf9 in a large production environment uploading files 300MB+ reliably (I mean 100% of the time it works). We are using the new flash upload control with cf9 cffileupload tag on a quad core linux and quad core win 2008 server both with 8GB Ram and nothing else running on either machine (and they are connected very well in major a data center) and still 1 out of 10 uploads fail to complete and die in the cf temp directory. We have 1GB of memory set in cf administrator for file uploads and the servers never break a sweat during uploads but the upload just mysteriously (not always) fails. It's been very frustrating as we have to build just this portion in php so we can rely on it and not get constant complaints from customers of failed file uploads and the dreaded 500 Error. I would love to hear real world feedback on this.
Do you see anything interesting in the logs when the upload fails?
Are you maybe hitting a process time limiter, like seefusion?
Nothing strange in the logs, basically the only way I know an upload is failed is a customer complaint and/or I see large tmp files sitting in the /opt/coldfusion9/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp directory. The problems seem to go away for a while once I a) clear these files and b) restart the cf service. As I say this is a very powerful server running nothing but this upload app and used by no more then 4 or 5 people at the same time max.
FYI - Settings I have in CF Administrator are
Maximum size of post data : 1000MB
Request Throttle Threshold : 4 MB
Request Throttle Memory : 1000MB
Does the timeout setting come into play with these uploads, could the problem be that simple? I have it set to 180 secs currently and several of these uploads would take longer than that. I can't imagine that value is used in the flash uploader cf is using. When the upload fails CF does issue the 500 error which displays in the uploader but as noted nothing shows in regular logs. However, I did just find some additional logs that may be capturing the error, from
opt/coldfusion9/runtime/logs/coldfusion-event.log
03/10 00:33:52 error unexpected end of part
java.io.IOException: unexpected end of part
at com.oreilly.servlet.multipart.PartInputStream.fill(PartInputStream.java:96)
at com.oreilly.servlet.multipa...(PartInputStream.java:191)
at com.oreilly.servlet.multipa...(PartInputStream.java:152)
at com.oreilly.servlet.multipart.FilePart.write(FilePart.java:257)
at com.oreilly.servlet.multipart.FilePart.writeTo(FilePart.java:215)
I did not include all of it as maybe these first few lines would shed some light on the source of the issue?
Sorry for not responding sooner. Unfortunately - I've got no idea on this one. Did you try "official" Adobe support? DId you try upping the timeout to over 180? Remember you can do it on a per request basis.
I am using CF MX and trying to get this to work to upload a file to a network server in my company. I have incorporated your code into my form. Problem one, the result attribute is not accepted. The message:
The tag does not have an attribute called result. The valid attribute(s) are action, charset, accept, destination, filefield, nameconflict, mode, attributes, source, file, variable, output, addnewline.
So I remove the result attribute.
Then the next error is: "Variable UPLOAD is undefined." I assume this is coming from the cfdump tag: <cfdump var="#upload#">. I am not sure how this is supposed to be working, and don't know what to do about it. (I'm obviously not an accomplished CF user.)
Pertinent code in my input form:
Select your code file: <input type="file" name="uploadfile">
Pertinent code in my action page, following the INSERT query:
<cfif structKeyExists(form, "uploadfile")>
<cfset destination = "\\dilbert\matlab\">
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload" filefield="uploadfile" destination="#destination#" nameConflict="makeUnique">
<cfdump var="#upload#">
Thank you for any guidance you can provide.
1) Right. result was added in 8. You are using a -very- old version of CF. In 7 the value is just saved into a variable structure called cffile.
2) Therefore, change Upload to CFFILE.
Two undesirable (possibly related) results from this fix. 1) I get a large "struct" table displayed on my acknowledgement page; and 2) the file didn't upload to my destination. Perhaps I am defining its location with incorrect syntax ("\\dilbert\matlab\")? (The folder absolutely exists on the server dilbert.)
The filepath to your destination is the full physical filepath. For example c:\dilbert\matlab (or whatever the actual value is). If you do not use this syntax to denote your filepath, then use the expandPath() function as so:
<cfset destination = expandPath('\\dilbert\matlab')>
As far as your cffile dump, you can pick a value out of that structure to use for display.
@Dale: How is 1 an issue? My code dumps so it is expected. As for 2 - does CF run as a user or System? CF can't write to network shares unless it runs as a user that has access.
@Troy: I disagree. You can use a network path as is as long as CF runs as a user with access.
@Troy: As per Raymond's subsequent comment, I left the line cfset destination = "\\dilbert\matlab">
@Raymond: I got our IT people to give CF full user access rights to the destination folder.
And the latest test worked! In part...
1) I have a field in my database which is supposed to hold the filename (which in my current test is matlabtest1.docx). The INSERT command in the operation that worked (insofar as the file was uploaded to \\dilbert\matlab) instead entered this into that field:
D:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp2403.tmp
The INSERT command looks like this:
INSERT INTO tblMatlab (initials, title, description, filename)
VALUES ('#Form.initials#', '#Form.title#', '#Form.description#', '#Form.uploadfile#')
I have apparently put the wrong variable name in #Form.uploadfile#.
2) I guess the issue with the dump is that I don't know what it is or why it is necessary, and I don't want my users to be confused by it. However, as I glance at the latest one output, I see it has a wealth of useful information and Matlab users will not be intimidated by it.
Thank you again. You are very generous to offer so much support to us mid- to low-level users.
Right - the dump is definitely NOT for the general public. I make use of cfdump a lot, especially in my demos here, but for _this_ post I should have removed it since i twas meant to a guide to getting the feature done on a 'real' site. Anyway - glad you got it all working, and you are most welcome.
I will leave cfdump in there, though, for my group of matlab users for this application--a shared code repository. It is very useful.
Still, how do I get the correct file name into my filename field in the database? Note the problem described above. Obviously #Form.uploadfile# is wrong, but I can't figure out what would be the right way to capture the correct file name.
Thanks.
Define "correct." :) The struct contains the name from the user's machine, it's cffile.clientfile i believe. (Check docs or above.) But if the file was renamed and you want that, use serverfile. Normally I store both. I need the serverfile so I can do crap with it later. But the user is shown the clientfile since that's the name THEY remember.
I am not being clear. The filename field in my database, which I am trying to populate with:
INSERT (..., filename)
VALUES (..., '#Form.uploadfile#')
SHOULD be populating that field with matlabtest1.docx, but instead is putting this into that field:
D:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp2412.tmp
You want to use the CFFILE struct, the thing you dumped? it contains _all_ the fields.
p.s. You also want to make use of cfqueryparam, but one thing at a time. ;)
Ah, Raymond, you are forgetting the extent of the ignorance of us (regrettably) casual users. I get what you are saying, but don't have a clue how to implement. Here is my .cfm file, in pertinent part. Where does my filename field get populated, and how?
<!--- Create record in tblMatlab --->
<cfquery name="qry1" datasource="Creare">
INSERT INTO tblMatlab (initials, title, description, filename)
VALUES ('#Form.initials#', '#Form.title#', '#Form.description#', '#Form.uploadfile#')
</cfquery>
<cfif structKeyExists(form, "uploadfile")>
<cfset destination = "\\dilbert\matlab">
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload" filefield="uploadfile" destination="#destination#" nameConflict="makeUnique">
<cfdump var="#cffile#">
</cfif>
<!--- Begin HTML Page to acknowledge update---> ....
By the way, I know I am using a very old ColdFusion. Problem is, the update cost is more than four times what I paid for the program in the first place! I suppose I will bite the bullet one day (when it will be even costlier), because I won't even be speaking the same language as the rest of the world's users.
You want to run the upload action first. After that, the cffile struct will contain all the data you need. What the file was - what it's called now - etc. You would then do your query.
Perfect! Works like a charm. Again, many thanks.
Back at you, I fear. This new capability has me going back to some old routines and updating them with this nifty upload.
You say somewhere that you can have multiple uploads on one form. How does the cffile dump distinguish among, say, four upload possibilities on one form? I have a form where the user updates a database record and can upload up to four photos to a photo repository folder. But I don't know how to phrase the INSERT command.
I hope I am being clear here. Let me know if I need to elaborate on this.
Thanks!
In order to process N uploads, you can use cffile action="uplaodAll", but that's CF9 only though. If you know the names of your file fields, then you need one cffile/action="upload" for each. Each tag will overwrite the CFFILE structure so you would need to process them one at a time, otherwise you 'lose' the data from the previous upload.
Hi, I've been googling for a while on this with no luck: is there any way to force the user to use the browse button to select a file to upload and prevent input in the text box? With type="file" it seems the text box and browse button are treated as a single entity, so properties like "readonly" and "disabled" affect the browse button as well as the textbox.
Like the new look Ray, very "velvet underground"
@mikep: Afaik no. File controls are locked down pretty hard since they represent something of a security issue. It's why you can't use JS to set the value.
@paul: thanks :)
I need one more piece here. In my user form, I have four lines like this:
Select photo file:</b> <input type="file" name="uploadfile1">
...
Select photo file:</b> <input type="file" name="uploadfile2">
etc.
And in my target file, I do the following (your code stripped down to what I think are the essentials):
<cfif structKeyExists(form, "uploadfile1")>
<cfset destination = "\\server\myfolder">
<cffile action="upload" filefield="uploadfile1" destination="#destination#" nameConflict="makeUnique">
<cfdump var="#cffile#">
</cfif>
...
<cfif structKeyExists(form, "uploadfile2")>
<cfset destination = "\\server\myfolder">
<cffile action="upload" filefield="uploadfile2" destination="#destination#" nameConflict="makeUnique">
<cfdump var="#cffile#">
</cfif>
... [for uploadfile3 and uploadfile4]
But then, I don't know what to do in my INSERT procedure because presumably my cffile.serverfile value will be the last one that was run.
INSERT INTO tblBlurbUpdate (... photofilename1, photocaption1, photofilename2, photocaption2, photofilename3, photocaption3, photofilename4, photocaption4)
VALUES (... '#cffile.serverfile#', '#Form.photocaption1#', '???', '#Form.photocaption2#', '???', '#Form.photocaption3#', '???', '#Form.photocaption4#')
The only thing I can think of is maybe inserting a <cfset tag> in your section somewhere, e.g.,
<cfset photofilename1 = #form.uploadfile1#
or something like that? Or is there some other way you would recommend?
Again, many thanks.
Yep, just copy the values out like you suggested.
I tried a form where I added a first picture but not the second, third, or fourth. When I click Submit, a cffile table is displayed, followed by the error "The form field "uploadfile2" did not contain a file." The photo is uploaded, but we never reach the INSERT command and no data record is created.
Here is the code section I think is provoking the error:
<!--- Photo 2 --->
<cfif structKeyExists(form, "uploadfile2")>
<cfset destination = "\\dilbert\corporate\projects\blurb_photos">
<cffile action="upload" filefield="uploadfile2" destination="#destination#" nameConflict="makeUnique">
<cfdump var="#cffile#">
<cfset photofilename2 = #form.uploadfile2#>
<cfelse>
<cfset photofilename2 = NULL>
</cfif>
Can you see what I am missing here?
Thanks.
When you submit the form, form.uploadfile2 does exist, but it is blank. Simply make your CFIF more robust
<cfif structKeyExists(form, "uploadfile2") and len(form.uploadfile2)>
That works!
Again, thanks for your generosity. I've learned a lot, very efficiently, and have added a most useful capability to my intranet.
Hi Ray,
i've just got a problem trying to upload an image from flex mobile application to server using cffile action upload.
I have a mobile app, which took image from camera and trying to upload to my server calling:
<s:RemoteObject id="photoUploadService" destination="ColdFusion" source="cfc.upload">
<s:method name="insertImageLocation" result="insertImageResultHandler(event)" fault="faultHandler(event)">
<s:arguments>
<picToUpload>{fileURL}</picToUpload>
</s:arguments>
</s:method>
</s:RemoteObject>
fileURL looks like this:file:///mnt/sdcard/forest/forest.jpg
Now cf part. I have a cfc with a function
<cffunction name="insertImageLocation" access="remote" >
<cfargument name="picToUpload" type="string" required="no">
<cfset var cffile = "">
<cffile action="upload" filefield="#arguments.picToUpload#" destination="d:\home\chi.am\wwwroot\testimages" nameConflict="makeUnique" result="upload">
</cffunction>
What am i missing?
Well, you didn't say how it was failing. Remember that filefield is supposed to be a form field name. So you probably wan't
<cffile action="upload" filefield="arguments.pictoUpload" ... >
It just does not upload. I really dont know how to catch that error.
I've used a sample from Matt's blog:http://www.chaosm.net/blog/...
I just want have it to post to cfc, so i can send more arguments to function, say insert a data to DB.
First, try the change I suggested. Secondly, check your CF logs. You can catch the error back in Flex, but it may be quickest just to look at your CF log files to see the error.
Ray,
I read through the thread and comments and I don't see a solution to a problem I am having that some people were also experiencing.
I have an issue where large files are timing out during an upload. My clients don't understand how to downsize images from 300 to 72 dpi so this gets very frustrating as it makes it look to them like my system is "broken".
Do you know of any solution whatsoever to either a) restrict someone from uploading a large file, or b) actually allow a large file to be uploaded. I would prefer a solution to 'b' of course but 'a' would be fine as well. :)
Any help would be extremely appreciated. btw I am on CF9.
Cheers
Why not just use maxuploadsize?
I am not using <cffileupload> because I am submitting a form which has other elements which need to be inserted into a db table for records and such.
I might be a complete idiot but you can't use a form with <cffileupload>...can you?
You are absolutely NOT an idiot. It's a subtle issue - cffileupload - the control I should say, is its "own process" so to speak. So can you use it with other form elements. Yes - if you are careful. Please try this guide:
http://www.coldfusionjedi.c...
hmmm..
This is a great example. The problem I see with it is validation that the file was uploaded prior to submitting the form. Perhaps an ajax response could enable the submit button so they couldn't click it unless at least one file was uploaded?
The other thing I see as an issue with this is that people are stupid. In my particular instance only one file needs to be uploaded. Even if I set the maxfileselect to 1, it still appears as if they could upload multiple files. The uploader I am trying to implement is a one file only uploader.
I can't have my clients thinking they can upload multiple files in this case. *sigh*
Also, what the heck is "ram:///portfoliouploads"? Does this save it to the physical memory or ColdFusion memory?
Thanks again :)
If you are only trying to upload one file - why are you using... oh wait... you AREN'T using cffileupload. Nm - brain fart on my side. So that being said - you still need a way to control size. So maxfileselect is _not_ working for you?
ram:/// is part of the Virtual File System. It's a CF9 feature. It's a RAM based virtual file system.
maxfileselect "works" as in it alerts the user that they can only select 1 file, but we are talking about users here. They wont get that. I can already hear the decries of "it's broken"...*shudders*
This little flexy interface is nice and all, and I will definitely use it for a multiple file upload system. However, uploading one file in a multiple file uploader seems kind of retarded. No disrespect :)
So yes, I am still stuck with limiting the file size of a user using <input type="file"...
Perhaps then I could use this Virtual File System?
The thing is - afaik - only the Flash SWF can get the size of the file before it's uploaded. It's not available in JS. You may have to simply deal with the users. You can add additional warnings above the control to make it more clear.
At some point - even clueless users - have to take _some_ responsibility for using a tool.
The VFS is not really related to your issue here. I mean you can use it - but it's not going to solve your concern if that makes sense.
I have an issue using cffile upload with the overwrite attribute. Seems if the file is currently in use, an "Access denied." exception is thrown. Is there a way to handle this? I have a simple PDF uploader that an admin uses to update a seminar agenda. Looks like if the file is in an "open" state by a Web user, this exception occurs.
try/catch should handle it.
Hi Ray,
I am uploading file from Flex4.5 app to coldfusion8. I need to send one variable with the fileRef.upload so based on the documentation, I am creating URLvariable and assigning it to the URLrequest.data (Please see below)
private function uploadLessonFile():void
{
/* qnFigFileRef.addEventListener(Event.COMPLETE, completeHandler);
qnFigFileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,dataHandler); */
var lessonUploadURL:URLRequest = new URLRequest();
var params:URLVariables = new URLVariables();
params.course = courseDropdown.selectedItem.courseID;
//~~~~~~~~~~~ For initializing File upload parameters (qn fig and qn swf etc. and setting event listners ~~~~~~~~~~~~~~~~~~~~~~~~~~~
lessonUploadURL.url = configVars.lessonCFMPath;
lessonUploadURL.method = "POST"; // OR "GET" as you need it
lessonUploadURL.data = params;
lessonUploadURL.contentType = "multipart/form-data";
lessonFileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
lessonFileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS,httpStatusHandler);
lessonFileRef.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
lessonFileRef.upload(lessonUploadURL,"Custom1");
}
The corresponding CFM is
<cfset req = getHTTPRequestData()>
<cffile action="upload"
destination="C:\temp\AnsSwf"
accept="application/octet-stream" FILEFIELD="Custom1"
nameconflict="makeunique"
/>
<cfdump var="#req#" format="html" output = "/temp/uploadLesson.html"/>
<cfdump var='URL' format="html" output = "/temp/uploadLesson.html"/>
<cfdump var="#CFFILE#" format="html" output = "/temp/uploadLesson.html"/>
The ISSUE is that I am not able to access the URL variables which I set from the flex app. It does upload the file correctly. When I do a CFDUMP of the #URL#, it is an empty structure.
Any thoughts?
Thank You,
Rajiv
Well, your dump is using "url", not "#URL#", so it won't work as is.
Hi Ray - I have tried all combinations "#URL#", "#url#","URL", '#URL#' but nothing is working. Of course when I put "url", it dumps the string "url" but in rest of the cases it just dumps an empty structure. (It does not throw any error).
Hi Ray - I discovered the fix. I need to pass the method as "GET" (instead of "POST"). Thanks for your quick reply though.
This article is good and brings up some good points.
Thanks again/
Hello. What should the data type for "uploadfile" be? I ask because I received a number of errors after trying to upload a pdf and docx. One of the errors stated that I need a uploadfile field in my table. Now I am receiving the following error after I added the field to my table: Invalid content type: "application/x-www-form-urlencoded". CFFILE action="upload" requires forms to use enctype="multipart/form-data". I also do have the enctype correct on my form.
"One of the errors stated that I need a uploadfile field in my table."
This implies you are trying to write information to a table and to a column that doesn't exist. Therefore it should be simple - add the column.
"Invalid content type: "application/x-www-form-urlencoded". CFFILE action="upload" requires forms to use enctype="multipart/form-data""
Best I can say for that is to double check.
Hi. What about uploading a file from a known location on the user's PC, without forcing them to select it first. I am specifically thinking of a logo file to be uploaded to an application which generates quotes on behalf of a Dealer. We don't want the hassle of keeping Logos up to date for the Dealers, so if they always put their current logo in, say, c:\logos\MyLogo.jpg we could just pick it up from there, and put it on our server prior to incorporating it into the generated document.
Thanks.
You can't do this as it would be a security violation.
Hey Raymond,
I am getting error if I hit upload file button without selecting a file - "The form field fileUpload did not contain a file."
Is there anyway to fix this out quickly
Many Thanks
Sure -
<cfif not structkeyExists(form, "fileupload") or not len(trim(form.fileupload))>
some error msg
</cfif>
Hello Ray,
I need a help. I am trying to browse a photo from Flex front end, upload & rename it from upload.cfm file. Everything works fine till this. After that I have to get the new name from upload.cfm to profile.mxml file, in order to save it in the Database.
file.addEventListener("complete", fileUploaded);
file.upload(urlRequest,"filedata",false);
var urlRequest:URLRequest = new URLRequest("http://localhost:8500/profile/components/upload.cfm");
private function fileUploaded(event:Event):void{
newImage.load("http://localhost:8500/profile/bin/applicantPics/"+event.target.name);
Users_Photo.text = event.target.name;
saveItem(this.detailObject);
}
Is there a way I can get the new filename from upload.cfm to profile.mxml.
Using the above code it is saving the old file name to the DB, as it happening in the front end.
Please help.
Many Thanks, Naisy
The new name is returned in the CFFILE structure. (I forget the exact key name, but it should be detailed above.) Your CFM needs to output this. Your Flex code would get it in the response.
Many thanks. It worked. You are a star!
Hi
i am facing problem from long time i.e invalid content type:application/x-www-form-urlencoded even after keeping multipart/form-data even though i have used enctype="multipart/for-data" form
I assume you mean form-data, not for-data?
Here is a question that's more about presentation than function. What controls the language rendered on the 'browse' button itself.
We have an application that uses CFFILE. we have set both the cf locale and the browser local to es-es, but the label on the browse button is 'BROWSE', not its spanish equivalent as we would expect. I can find no documentation about how to set the text on this label.
Can anyone offer advice?
Remove CF from the equation. When you use a input/type=file on a HTML page, is it localized? Are you sure the browser settings are using your correct locale?
You can also bind another UI item to a file upload control: http://stackoverflow.com/qu...
@Ray
re first question: It's localized and we set the browser locale, but have no way of knowing if the user overrides.
re your second comment... it's brilliant. You just gave me a couple of ideas; I'll write back after I've tried a couple of experiments. It didn't occur to me to 'fix it' at the browser side rather than the CF side. I've been trying to peek into an opaque box when I can just fix it after the HTML is rendered.
BTW, first time corresponding even though I've been working with ColdFusion for about 15 years and been following your work for a long time.
Your contribution to the community is immeasurable. Thanks!
"re first question: It's localized and we set the browser locale, but have no way of knowing if the user overrides."
But why would you care? If I (the user) really wants language X for my UI, why would you want to overrule me?
LOL. Because the same customer is complaining that the button isn't rendering in Spanish.
Give them what they want, not what they're asking for. :-)
Then you'll probably have to use option 2 then - which sounds like it is something you like anyway. :)
I know this thread is ancient, but it may be useful for others. In my experience, if the directory containing the file with this code does not have full write access, it will not create the directory. I know that on my server permissions are 775 by default for areas to which I have access. If I run this code I get an error. But if I change the directory to have permissions 777, the directory is created. Once the sub directory is created, however, permissions of 775 on the parent directory, work just fine. All this presumes you have access to change permissions of course.
Thanks for sharing - old post or not. :)