Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

cffile action="write" charset="utf-8" - problem

Hello experts.
I did upload recently my firt webpage but i had a lot of troubles with charset and unicode.
The  page was working fine on my local pc but unfortunately i was not so lucky on the hoster. The reason was that the default language on my machine was greek.(below is the full explanation from hoster).I did change all my .cfm pages to utf-8. It is working now but i have to solve a couple of problems.
In this question i need a solution to get a text file using cffile write with encoding utf-8.
Using charset=utf-8     i get a text file utf-8 non BOM. and unfortunately odd characters.
I have to change it manually with notepad to only utf-8 and uploaded again.
Any help?

<cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" addnewline="yes" charset="utf-8">


(hoster explanation for unicode:
The server where your site resides is using Windows 2008 RK2 and has a default installation with English(United States) set for locale and for "Current language for non-Unicode programs". If a file with non-latin characters is saved as ANSI, server will by default try to read it using English encoding.  On your pc (depending on OS) you most likely have locale set to Greece or non-unicode language set as Greek, or default encoding table set to something like Greek(1253). This will allow you to read and save files as ANSI and still be able to see the correct characters without marking them as utf-8.
)
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

<!--- ADD THESE TO THE BEGINNING OF YOUR PAGE --->

<cfprocessingdirective pageencoding="utf-8">
<CFCONTENT TYPE="text/html; charset=utf-8">


<cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" addnewline="yes" charset="utf-8">
Avatar of Panos

ASKER

Hi brijeshchauhan
the cffile is a cfc file.
i put the <cfprocessingdirective pageencoding="utf-8">  line on the top and got the error page
put it in your function which you call to upload the file..

<cffunction ...
   <cfargument ....
         
            <cfprocessingdirective pageencoding="utf-8">
          <CFCONTENT TYPE="text/html; charset=utf-8">

                    <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" addnewline="yes" charset="utf-8">
          </cfprocessingdirective>
</cffunction>
Avatar of Panos

ASKER

Here is the function.
Please place the code in the right place because i'm getting again the error page.
<cfcomponent>
<cffunction ........>
 <cfargument .........>
       <cfquery name = "qryCompanyInfo" datasource="#cfdsn#">
         ........
        </cfquery>

        <cfquery name = "qryButtons" datasource="#cfdsn#">
           .........
		<!---clear file--->
		<cffile action = "write" file="#path#config#request.bslash#settings.cfm" output="" charset="utf-8" mode="777">

		<!---write main settings--->
       
            
        <cfloop from="1" to = "#listlen(col_list)#" index="c">
            <cfset .....
        
        
            
            <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" charset="utf-8" addnewline="yes">
        </cfloop>
		
        <!---write buttons--->
        <cfloop query = "qryButtons">
            <cfset ....
        
            
            <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" addnewline="yes">
        </cfloop>

	</cffunction>
</cfcomponent>

Open in new window

Just add the cfprocessingdirectivedirective, before you begin the loop.. see in bold below.. (Let's just add cfprocessingdirective and test it out.. )

<cfcomponent>
<cffunction ........>
 <cfargument .........>
       <cfquery name = "qryCompanyInfo" datasource="#cfdsn#">
         ........
        </cfquery>

        <cfquery name = "qryButtons" datasource="#cfdsn#">
           .........
            <!---clear file--->
            <cffile action = "write" file="#path#config#request.bslash#settings.cfm" output="" charset="utf-8" mode="777">

            <!---write main settings--->
        <cfprocessingdirective pageencoding="utf-8">   <!--- Add processing directive --->
        <cfloop from="1" to = "#listlen(col_list)#" index="c">
            <cfset .....
       
       
           
                  <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" charset="utf-8" addnewline="yes">
        </cfloop>
        </cfprocessingdirective><!--- END processive directive --->
            
        <!---write buttons--->
        <cfloop query = "qryButtons">
            <cfset ....
       
           
            <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" addnewline="yes">
        </cfloop>

      </cffunction>
</cfcomponent>
Avatar of Panos

ASKER

It is generating the error page again.
hmmmm..

you are writing to the file

#path#config#request.bslash#settings.cfm

so in your settings.cfm, do you have


<CFCONTENT type="text/html; charset=utf-8">
<CFPROCESSINGDIRECTIVE pageencoding="UTF-8">

Open in new window


added at the top ?

please remove the processivedirective from the CFC.... and add it to settings.cfm file..
Avatar of Panos

ASKER

Ok.
i don't get odd characters adding the code in the top of the settings page but when i update my form the cfc page clearing the page and rewriting all the code.
I must write the code again.Can you do it in the function?
Avatar of Panos

ASKER

you will the code below:
<cfset col_list = qryCompanyInfo.columnlist>
           
        <cfloop from="1" to = "#listlen(col_list)#" index="c">
            <cfset thiscol = listgetat(col_list, c)>  
            <cfset requestvar = 'request.#thiscol#'>
            <cfset requestval = 'qryCompanyInfo.#thiscol#'>
            <cfset requestval = evaluate(requestval)>
       
           <cfif NOT requestval CONTAINS "'">
                        <cfset thisline = "<cfset #requestvar# = '#requestval#'>">
            <cfelse>
                  <cfset thisline = '<cfset #requestvar# = "#requestval#">'>
            </cfif>
           
            <cffile action = "append" file="#path#config#request.bslash#settings.cfm" output="#thisline#" charset="utf-8" addnewline="yes">
        </cfloop>
ASKER CERTIFIED SOLUTION
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

That's it.
This is a very very good solution.
I'm trying to solve this 2 days now.

Thank you very much.
Avatar of Panos

ASKER

Thank you verymuch
regards
panos