Reputation: 11
I am struggling with the following cffile code. I am trying to pass a dynamically generated images directory, the name of which is stored in a session variable (one for each new member). I need to pass that name to the destination attribute of the cffile tag:
Heres my code for processing the file upload
<cfset mypath=expandpath('UserImages/UploadedImages/' & '#session.details.uimages#')>
<cffile action="upload" destination="#mypath#" nameconflict="makeunique"/>
The upload works fine if I replace the #session.details.uimages# with an actual directory name. Is, what I am trying to do, achieveable or is this not possible?
Any help, or guidance will be welcomed as I am tearing my hair out!
Thank you all in advance!
Upvotes: 0
Views: 492
Reputation: 112160
If the directory doesn't exist, you need to create it first.
If uimages comes from the user, don't forget to first verify it is a valid directory name (and specifically, that it doesn't contain path traversal syntax, i.e. ..
).
Also, your cffile lacked the filefield attribute, which is required.
Note as well the lack of hashes around the session variable - they are unnecessary.
<cfset MyPath = expandPath( 'UserImages/UploadedImages/' & session.details.uimages ) />
<cfif NOT DirectoryExists( MyPath )>
<cfset DirectoryCreate( MyPath ) />
</cfif>
<cffile
action = "upload"
destination = "#MyPath#"
nameconflict = "makeunique"
filefield = "name_of_field_to_upload_from"
/>
Upvotes: 6