gsr
04/06/2025, 12:07 PMTagr's Area
when i upload it shows:
Tagr�s Area
i tried everything , using cfprocessingdirective
utf in upload and reading but during upload, it just reads it and displays as wrong, i even tried using the htmlentitieszackster
04/06/2025, 5:19 PMgsr
04/06/2025, 5:57 PMgsr
04/06/2025, 5:59 PMgsr
04/06/2025, 6:48 PM<!--- Set UTF-8 encoding for the page --->
<cfprocessingdirective pageencoding="utf-8">
<CFCONTENT TYPE="text/html; charset=utf-8">
<!--- Form to upload CSV file --->
<form action="#cgi.script_name#" method="post" enctype="multipart/form-data">
<input type="file" name="csvFile" accept=".csv">
<button type="submit">Upload and Display CSV</button>
</form>
<!--- Process uploaded file --->
<cfif structKeyExists(form, "csvFile")>
<!--- Upload file to temp location --->
<cffile
action="upload"
filefield="csvFile"
destination="#getTempDirectory()#"
nameconflict="overwrite"
result="uploadResult"
>
<!--- Read file with UTF-8 encoding --->
<cffile
action="read"
file="#uploadResult.serverdirectory#/#uploadResult.serverfile#"
variable="csvContent"
charset="utf-8"
>
<!--- Parse CSV content with HTML entity handling --->
<cfset csvArray = arrayNew(2)>
<cfloop index="line" list="#csvContent#" delimiters="#chr(10)#">
<cfset row = arrayNew(1)>
<!--- Convert HTML entities to characters --->
<cfset processedLine = line>
<cfdump var="#processedLine#">
<!--- Split by comma, preserving quoted fields --->
<cfset fields = reMatch('(".*?"|[^",]+)(?=\s*,|\s*$)', processedLine)>
<!--- Add each field to the row --->
<cfloop array="#fields#" index="field">
<!--- Remove wrapping quotes if present --->
<cfif left(field, 1) == '"' AND right(field, 1) == '"'>
<cfset field = mid(field, 2, len(field)-2)>
</cfif>
<cfset arrayappend(row, field)>
</cfloop>
<cfset arrayappend(csvArray, row)>
</cfloop>
<cfoutput>
<!--- Display results --->
<table border="1">
<cfloop array="#csvArray#" index="row">
<tr>
<cfloop array="#row#" index="cell">
<td>#cell#</td>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
<!--- Clean up temporary file --->
<cffile
action="delete"
file="#uploadResult.serverdirectory#/#uploadResult.serverfile#"
>
</cfif>Tomy Saman
04/07/2025, 12:28 AMgsr
04/07/2025, 9:52 AM