David Brierton
David Brierton

Reputation: 7397

Duplicating and Renaming a file and storing name in Database

I have a register page that asks for information like employee_number, user_name, user_pass, firstname, lastname, position, email, phone_extension, department, picture. Once they fill this information out and they hit register it all gets uploaded into a database.

Is it possible to have it create a profile page specific to that user based on the information in the database?

For example, if I registered to have it create DavidBriertonProfile.cfm from my template Profile.cfm and have it add DavidBriertonProfile.cfm in the database so I can use that name to reference later. But is it possible to take my template Profile.cfm and rename it based on there name and have it added to profiles/(TherenameProfile).cfm

I have been playing with cffile in order to create a path but I need it to be behind the scenes selecting my template file where the user never sees any of this.

<cffile 
     action       = "upload" 
     file         = "#expandPath("/webapps/dash/profiles/profile.cfm")#"
     destination  = "#expandPath("/webapps/dash/profiles/")#" 
     nameConflict = "MakeUnique" 
     result       = "myfile" 
   /> 

Upvotes: 1

Views: 89

Answers (1)

Dan Roberts
Dan Roberts

Reputation: 4694

There are two primary options

Create a static file from a coldfusion template...

<cfsavecontent variable="filecontent">
    <cfinclude template="profile.cfm" />
</cfsavecontent>
<cffile action="write" file="profiles/#FirstNameLastName#Profile.html" output="#filecontent#" />
<!--- it looks like the "nameconflict" option is only available for upload action so will have to deal with that --->

Create a file just for setting the userid and including profile.cfm

<cffile action="write"
    file="profiles/#FirstNameLastName#.cfm"
    output="<cfset userid ='#UserID' /><cfinclude template='../profile.cfm' />"
/>

Some other options include

  • Save the name of the unique cfm file you would create (ex: DavidSmith12Profile) but don't actually create it and instead use the OnMissingTemplate function in Application.cfc to take the name supplied and perform a database lookup and then show the profile result

  • Peform a URL rewrite on the webserver to transform any request to paths of format /profiles/(.+) to /profile.cfm?filename={\1} and then do a database lookup by the filename directly in profile.cfm

enjoy

Upvotes: 1

Related Questions