Skip to main content
Inspiring
November 3, 2008
Question

Filename: Replace spaces with underscores

  • November 3, 2008
  • 1 reply
  • 1161 views
Greetings,

I have searched the forum and online and have not found an answer.
So posting here for assistance.

What is the proper syntax for replacing spaces in file names with under
scores prior to cffile upload? -or- what is the best method to accomplish
this process?

Example:
document name.doc >> document_name.doc

Thanks

Leonard
    This topic has been closed for replies.

    1 reply

    Inspiring
    November 3, 2008
    you can't change the filename before the file has been uploaded to your
    server.

    upload a file using cffile.
    #cffile.serverfile# variable will contain the name with which the file
    has been saved on your server.
    check if the name contains any spaces using find() cf function.
    if it does, use cffile action="copy" to copy the file as a file with no
    spaces in the name (use replace() cf function to replace spaces with
    whatever you want).
    [you may want to make sure prior to copying the file that there is not
    already a file with same name (with no spaces) in that folder, otherwise
    the copy action will overwrite existing file]
    delete original file.

    details of all the functions are in the CFML Reference. if you do not
    have one - download free from adobe.com

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/