[thelist] Bypass limit on memo field >> outputing to a text file auto...

.jeff jeff at members.evolt.org
Sat Aug 4 12:19:52 CDT 2001


kevin,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Kevin
>
> How would you define the variable setup so that I can
> create a variable to hold the file names for both the
> cfset and the file path?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

if you don't care if the filename tells you anything about the content, then
i'd suggest using the CreateUUID() function to create the filename.

<cfparam name="form.article_id" default="0">
<cfparam name="form.file" default="">

<cfif NOT Val(form.article_id)>
<!--- this is a new article so we need
      to do an insert query --->

  <cfset form.file = CreateUUID() & ".txt">
  <cfset path = "F:/Inetpub/wwwroot/mysite/content/" & form.file>
  <cffile
   action="write"
   file="#path#"
   output="#Trim(form.article)#">

  <cfquery name="insertarticle">
    INSERT INTO article (title, article)
         VALUES ('#Trim(form.title)#', '#Trim(file)#')
  </cfquery>

<cfelse>

  <cfset path = "F:/Inetpub/wwwroot/mysite/content/" & form.file>
  <cffile
   action="write"
   file="#path#"
   output="#Trim(form.article)#">

  <cfquery name="updatearticle">
    UPDATE article
       SET title = '#Trim(form.title)#'
     WHERE id = #Val(form.article_id)#
  </cfquery>

</cfif>

if you would prefer that the files have a naming scheme that's indicative of
the content it contains, then you might consider naming the files with
something that tells you what table and what record in that table the file
pertains to.

<cfparam name="form.article_id" default="0">
<cfparam name="form.file" default="">

<cfif NOT Val(form.article_id)>
<!--- this is a new article so we need
      to do an insert query --->

  <cftransaction>
    <cfquery name="insertarticle">
      INSERT INTO article (title)
           VALUES ('#Trim(form.title)#')
    </cfquery>
    <cfquery name="getmax">
      SELECT Max(id) AS id
        FROM article
    </cfquery>
  <cfset form.file = "article_" & getmax.id & ".txt">
  <cfset path = "F:/Inetpub/wwwroot/mysite/content/" & form.file>
  <cffile
   action="write"
   file="#path#"
   output="#Trim(form.article)#">
  <cfquery name="updatearticle">
    UPDATE article
       SET article = '#Trim(form.file)#'
     WHERE id = #Val(getmax.id)#
  </cfquery>

<cfelse>

  <cfset path = "F:/Inetpub/wwwroot/mysite/content/" & form.file>
  <cffile
   action="write"
   file="#path#"
   output="#Trim(form.article)#">

  <cfquery name="updatearticle">
    UPDATE article
       SET title = '#Trim(form.title)#'
     WHERE id = #Val(form.article_id)#
  </cfquery>

</cfif>

in this scenario you wouldn't even need to store the filename as you would
have all the information you'd need in the name of the file itself.

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list