Skip to main content
Dani Szwarc
Inspiring
October 20, 2009
Question

Changing the uploaded file extension

  • October 20, 2009
  • 1 reply
  • 1680 views

Hello people. I'm trying to find a way to change the file extension using CFFILE.ServerFileExt after a file has been uploaded.

Basically, I want to change the extension to "AI" if the uploaded file is a PDF file.

I know how to check the extension but I'm lost on how to modify it.

Thanks a lot for any help.

    This topic has been closed for replies.

    1 reply

    Inspiring
    October 20, 2009

    Basically, I want to change the extension to "AI" if the

    uploaded file is a PDF file.

    If you want to change how the file is stored on your physical file system, you must rename the file. See the documentation on cffile action="rename".

    Dani Szwarc
    Inspiring
    October 20, 2009

    Thanks for your answer, but I couldn't understand how to change the extension using cffile action="rename". If I'm not wrong, the rename action refers to the whole file, name.extension. I just need to modify the extension before I insert the info in my database, so instead of inserting "test.pdf", which is the uploaded file, I insert "test.ai".

    Thank you

    Dani Szwarc
    Inspiring
    October 20, 2009

    The CFFILE variables also provide the file name without the extension.  Just use a simple CFIF statement to change the file extension when it is "pdf".

    <cfset fileNameToInsert = serverFileName &"."& serverFileExt>

    <cfif CFFILE.serverFileExt eq "pdf">

         <cfset fileNameToInsert = serverFileName & ".ai">

    </cfif>

    Then insert the calculated file name into your database.  But, keep in mind that has no effect on the physical file.  The actual file on your file system will still be named "test.pdf".


    cfsearching, thanks for your answer, but I do need the file extension to change as well. I need to be able to display the link to the file and get Illustrator to open when this link is clicked.

    Dani