Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Update: If you are displaying the file with cfcontent/cfheader, another option is to store the original file name. Then change the cfheader file extension. I am not familiar with Illustrator, but I am assuming that would work the same as it does for other file types.
<cfheader name="Content-Disposition" value="filename=test.ai">
<cfcontent ....>
Then you are back to what I said earlier. You must rename the _physical_ file on your file system. Then insert the new name into your database.
To do the rename you will need to construct two paths: the path to the original file (test.pdf) and the path to the renamed file (test.ai). After uploading, CFFILE provides plenty of variables about the saved file, just consult the documentation. You can easily use these variables to construct the file paths:
CFFILE.serverDirectory
CFFILE.serverFileName
CFFILE.serverFileExt
Step 1. Construct the full path to the original file. Example: c:\someFolder\test.pdf
Step 2. Construct the path to the renamed file: Example c:\someFolder\test.ai
Step 3. Rename the file on your file system using CFFILE action="rename" and the paths from Step 1 and 2
Step 4: Insert the renamed file name into your database
Copy link to clipboard
Copied
Thanks again for your answer. Let me go back then to my original question: how do I use CFFILE.serverFileExt to change the extension? I searched online and posted the question in other forum too. I've noticed how to check the type of file, but no how to change it (not converting the file, just the change, since Illustrator will still open the file if the extension is changed manually).
Thanks again.
Copy link to clipboard
Copied
Thanks again for your answer. Let me go back then to my original question: how do I use CFFILE.serverFileExt to change the extension?
Sorry, I totally misread your original requirement and caused confusion. (I do not use Illustrator)
I am assuming you are using CFCONTENT for downloading the files. In which case, you need onlychange the "filename" in the Content-Disposition header. That header controls the file name displayed during downloading.
<cfheader name="Content-Disposition" value="attachment; filename=test.ai">
<cfcontent type="somemimetype here" file="C:\pathToYourFile\test.pdf" deleteFile="no">
There are at least two options for converting the file "test.pdf" to "test.ai". Option #1, have two columns in your database: physicalFileName and downloadFileName. Option #2, use list functions on your download page, to change the _header_ file name on-the-fly.
Copy link to clipboard
Copied
Thanks a lot!