Panos
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#se ttings.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.
)
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
(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.
)
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
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#se ttings.cfm " output="#thisline#" addnewline="yes" charset="utf-8">
</cfprocessingdirective>
</cffunction>
<cffunction ...
<cfargument ....
<cfprocessingdirective pageencoding="utf-8">
<CFCONTENT TYPE="text/html; charset=utf-8">
<cffile action = "append" file="#path#config#request
</cfprocessingdirective>
</cffunction>
ASKER
Here is the function.
Please place the code in the right place because i'm getting again the error page.
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>
Just add the cfprocessingdirectivedirec tive, 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#se ttings.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#se ttings.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#se ttings.cfm " output="#thisline#" addnewline="yes">
</cfloop>
</cffunction>
</cfcomponent>
<cfcomponent>
<cffunction ........>
<cfargument .........>
<cfquery name = "qryCompanyInfo" datasource="#cfdsn#">
........
</cfquery>
<cfquery name = "qryButtons" datasource="#cfdsn#">
.........
<!---clear file--->
<cffile action = "write" file="#path#config#request
<!---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
</cfloop>
</cfprocessingdirective><!
<!---write buttons--->
<cfloop query = "qryButtons">
<cfset ....
<cffile action = "append" file="#path#config#request
</cfloop>
</cffunction>
</cfcomponent>
ASKER
It is generating the error page again.
hmmmm..
you are writing to the file
#path#config#request.bslas h#settings .cfm
so in your settings.cfm, do you have
added at the top ?
please remove the processivedirective from the CFC.... and add it to settings.cfm file..
you are writing to the file
#path#config#request.bslas
so in your settings.cfm, do you have
<CFCONTENT type="text/html; charset=utf-8">
<CFPROCESSINGDIRECTIVE pageencoding="UTF-8">
added at the top ?
please remove the processivedirective from the CFC.... and add it to settings.cfm file..
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?
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?
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#se ttings.cfm " output="#thisline#" charset="utf-8" addnewline="yes">
</cfloop>
<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
</cfloop>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's it.
This is a very very good solution.
I'm trying to solve this 2 days now.
Thank you very much.
This is a very very good solution.
I'm trying to solve this 2 days now.
Thank you very much.
ASKER
Thank you verymuch
regards
panos
regards
panos
<cfprocessingdirective pageencoding="utf-8">
<CFCONTENT TYPE="text/html; charset=utf-8">
<cffile action = "append" file="#path#config#request