errorNumber = 0; fileName = cffile.ClientFileName; fileExt = cffile.ServerFileExt; // munge filename for html download. Only a-z, 0-9, _, - and . are allowed if( reFind("[^A-Za-z0-9_\-\.]", fileName) ) { fileName = reReplace(fileName, "[^A-Za-z0-9\-\.]", "_", "ALL"); fileName = reReplace(fileName, "_{2,}", "_", "ALL"); fileName = reReplace(fileName, "([^_]+)_+$", "\1", "ALL"); fileName = reReplace(fileName, "$_([^_]+)$", "\1", "ALL"); } // When the original filename already exists, add numbers (0), (1), (2), ... at the end of the filename. if( compare( cffile.ServerFileName, fileName ) ) { counter = 0; tmpFileName = fileName; while( fileExists("#currentFolderPath##fileName#.#fileExt#") ) { counter = counter + 1; fileName = tmpFileName & '(#counter#)'; } }