|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
CFFILE upload/read error with spaces in filename
I have a little thing where users upload a tab-delimited .txt file using CFFILE upload and read. It works perfectly UNLESS the text file the user uploads has a space in the file name.
I'd like to either make it so the file uploaded DOESN'T have a space in the filename (CFFILE rename?), or just produce a simple error message explaining to the user that filenames can't have spaces in them (something more friendly than the ugly CF error message). Either one would make me happy...this is my first time playing with CFFILE, so I'm not sure what can be done, or what's easier. Here the code if it helps: Code:
<cffile action="upload" destination="/home1/web-docs-443/files" nameConflict="overwrite" mode=777 fileField="FiletoUpload"> <cffile action="read" file="/home1/web-docs-443/files/#cffile.ClientFileName#.#cffile.ClientFileExt#" variable="UploadedFile"> Any suggestions/help would be much appreciated, thanks ![]() |
|
#2
|
|||
|
|||
|
You could use Javascript on the client to ensure the file has no space in the name. You could use the CFML find or REFind functions to ensure the file name has no space after it is uploaded. You can also use cftry/cfcatch to catch any errors and display friendly error messages to the user (that's what exception handling is for).
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
I must be missing something, because whenever I try to use functions (Find, Replace, etc) on the "FiletoUpload" variable it's checking the CONTENTS of the text file instead of the actual filename(?)
For example, just to test, before all the CFFILE stuff I put <CFOUTPUT>#FiletoUpload#</CFOUTPUT> Shouldn't that show the filename instead of the contents of the actual file? Here's the form from the page before where the user browse's their PC and selects the file to upload... Code:
<FORM action="self-report-check.cfm" enctype="multipart/form-data" method="post"> Enter the complete path and filename of the tab-delimited text file to upload:<BR> <INPUT TYPE="file" NAME="FiletoUpload" SIZE="45"> <BR><BR><INPUT TYPE="Submit" VALUE="Upload"> </FORM> I did put some CFTRY tags around the CFFILE stuff on the next page, which of course caught the error and created a better looking error screen, but this still seems too easy to be difficult. |
|
#4
|
|||
|
|||
|
Do a cfdump of the cffile structure to see what variables are available.
And personally I think using cftry/cfcatch is very easy. Remember it's up to you to handle exceptions and a space in the file name is an exception. That's what try/catch is there for. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > CFFILE upload/read error with spaces in filename |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|