I would store the DNS username and password in the CF Administrator if
possible.  You should also be using cfqueryparam on your inserts.  Every one
of them without fail.

Mike



-----Original Message-----
From: Eric Nicholas Sweeney [mailto:[email protected]] 
Sent: Thursday, July 14, 2011 4:18 PM
To: cf-newbie
Subject: RE: Creating a Link to a Recently Uploaded File


Michelle - here what I Do:

After Uploading I save the following 
File Directory is where the file is saved - in my case - it is a preset list
of directories - but you could easily swap that with something like
"/media/files/#variables.ThisPageID#" - I use to do that...

Additionally I have an additional table of FileLinks - that link files to
pages - so one file can be listed on multiple pages...

To Save:
<cfquery datasource="#Application.DSN#" username="#Application.username#"
password="#Application.password#">
        INSERT INTO Files (FTID, FileDirectory, Filename, Description,
PostedBy, PostedDate) VALUES (
  <cfif IsDefined("FORM.FTID") AND #FORM.FTID# NEQ "">
    '#FORM.FTID#'
      <cfelse>
      NULL
  </cfif>
  , 
  <cfif IsDefined("FORM.DestinationDirectory") AND
#FORM.DestinationDirectory# NEQ "">
    '#FORM.DestinationDirectory#'
      <cfelse>
      NULL
  </cfif>
  , 
  <cfif IsDefined("FORM.file_path") AND #FORM.file_path# NEQ "">
    '#CFFile.ServerFile#'
      <cfelse>
      NULL
  </cfif>
  , 
  <cfif IsDefined("FORM.Description") AND #FORM.Description# NEQ "">
    '#FORM.Description#'
      <cfelse>
      NULL
  </cfif>
  , 
  <cfif IsDefined("FORM.PostedBy") AND #FORM.PostedBy# NEQ "">
    '#FORM.PostedBy#'
      <cfelse>
      NULL
  </cfif>
  , 
  <cfif IsDefined("FORM.PostedDate") AND #FORM.PostedDate# NEQ "">
    '#FORM.PostedDate#'
      <cfelse>
      NULL
  </cfif>
 )
  </cfquery>
<!--- Step Two: Get new File ID  --->
        <cfquery name="qryGetNewFileID" datasource="#Application.DSN#"
username="#Application.username#" password="#Application.password#">
        SELECT Files.FileID
        FROM  Files
        ORDER BY FileID Desc
        LIMIT 1
        </cfquery>
                <cfset variables.NewFileID = #qryGetNewFileID.FileID#>

<!--- Step Three: Insert Into File Links --->
          <cfquery datasource="#Application.DSN#"
username="#Application.username#" password="#Application.password#">
          INSERT INTO FileLinks (FileID, Sort, PageID, PageType) VALUES (
          # variables.NewFileID#, 1, #FORM.PageID#, #FORM.PageType#
                )
          </cfquery>




To Retrieve:
<!--- Get Files --->
<cfquery name="qryGetFiles" datasource="#Application.DSN#"
username="#Application.username#" password="#Application.password#">
                        SELECT Files.*, FileLinks.*
                        FROM Files, FileLinks
                        WHERE FileLinks.PageID = #URL.PageID#
                                        AND Files.Active = 1
                        AND Files.FileID = FileLinks.FileID
                        ORDER by FileLinks.Sort ASC
</cfquery>

- Nick





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:5368
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm

Reply via email to