1

I'm trying to create link for the file upload. I'm calling file upload function from .cfc file. The file should be uploaded in a different folder. Here is what I get if after this code is executed in component.cfc page:

<cfset thisPath = ExpandPath( "./" ) />

C:\\wwwroot\\myapp\\components\\

I need to go level back in myapp and open bug folder. Then in a bug folder I need to direct the path either to folder1/ documents or folder2/documents. That will depend on the form field, here is example:

<cfset folder = trim(form.type) EQ 1 "folder1" : "folder2">

The path should either point to:

C:\\wwwroot\\myapp\\bug\\folder1\\documents\\

or

C:\\wwwroot\\myapp\\bug\\folder2\\documents\\

I'm looking for a solution that will work even if I roll this code to a different server with the same directory structure. Is there a good way to achieve this in ColdFusion?

espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
  • If you know what the path is going to be why not just hard code it? This seems like an application level setting to me and I would just set it as such. – Miguel-F Nov 19 '18 at 14:37
  • Agree with @Miguel-F that this could be considered a config setting for your app. If you don't have a way to set config settings for your app, maybe look at doing that. Also, I keep code separate from data, so uploads never go into code directories. Data directories are mapped to be accessible through the web server, so they can reside anywhere. To do this, you would specify the physical location, and the link location of your data via some sort of config setting. – Redtopia Nov 19 '18 at 18:27
  • Use the `onApplicationStart` event to search the webroot of the application and store it either using a mapping `this.mapping["/"] = path` or in a shared variable scope such as `application`. [Here is one approach to look for the root](https://www.petefreitag.com/item/630.cfm) - `Application.cfm` can be simply replaced with `Application.cfc`. – Alex Nov 19 '18 at 19:32

0 Answers0