Writing a UTF8 text file to server.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing a UTF8 text file to server.

Bob Sneidar via use-livecode
I am using Livecode Server on Livecode's hosting plan.

Taking my first stab at a web response form. I am getting the data from
$_POST fine, and when I simply do something like:
put $_POST[firstname]

the UTF8/Kanji word shows up fine in the webpage. But I am unable to
save the data to a file on the server encoded in UTF8 (simply trying to
collect the submitted data).

put "data.txt" into vfile
open file vfile for utf8 text update
put $_POST[firstname] & comma & $_POST[lastname] & comma &
$_POST[country] &  the time & return into vdata
write vdata to file vfile at end
close file vfile

Data is getting saved, but in gibberish, not in kanji/utf8.

Anyone see what I'm doing wrong?

TIA

Tim Selander
Tokyo, Japan


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Writing a UTF8 text file to server.

Bob Sneidar via use-livecode
Hello Tim,

Did you look at the textEncode function?


Scott Morrow

> On Oct 3, 2018, at 10:22 PM, Tim Selander via use-livecode <[hidden email]> wrote:
>
> I am using Livecode Server on Livecode's hosting plan.
>
> Taking my first stab at a web response form. I am getting the data from $_POST fine, and when I simply do something like:
> put $_POST[firstname]
>
> the UTF8/Kanji word shows up fine in the webpage. But I am unable to save the data to a file on the server encoded in UTF8 (simply trying to collect the submitted data).
>
> put "data.txt" into vfile
> open file vfile for utf8 text update
> put $_POST[firstname] & comma & $_POST[lastname] & comma & $_POST[country] &  the time & return into vdata
> write vdata to file vfile at end
> close file vfile
>
> Data is getting saved, but in gibberish, not in kanji/utf8.
>
> Anyone see what I'm doing wrong?
>
> TIA
>
> Tim Selander
> Tokyo, Japan
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Writing a UTF8 text file to server.

Bob Sneidar via use-livecode
Hi Scott,

Added info; I have <?lc put header "Content-Type: text/html;
charset=UTF-8" ?> at the top of the web page source.

Then, I only found outputTextEncoding in the dictionary. It said it only
works with CGI (server), put when I put:
set the outputTextEncoding to "utf-8"

into the script before dealing with the $_POST array, it broke the Kanji
on the web page itself.

Googling turned up info on the textEncode function, but this script
still results with a saved file of gibberish and not Kanji.

Changed the script to this:
put $_POST[firstname]      --(Results in Kanji name to web page)
put "data.txt" into vfile
open file vfile for utf8 text update
put textEncode($_POST[firstname], "UTF-8") into vdata
write vdata to file vfile at end
close file vfile

but still get a file with broken kanji.

Any hints?

Tim




On 2018/10/04 15:08, scott--- via use-livecode wrote:

> Hello Tim,
>
> Did you look at the textEncode function?
>
> —
> Scott Morrow
>
>> On Oct 3, 2018, at 10:22 PM, Tim Selander via use-livecode <[hidden email]> wrote:
>>
>> I am using Livecode Server on Livecode's hosting plan.
>>
>> Taking my first stab at a web response form. I am getting the data from $_POST fine, and when I simply do something like:
>> put $_POST[firstname]
>>
>> the UTF8/Kanji word shows up fine in the webpage. But I am unable to save the data to a file on the server encoded in UTF8 (simply trying to collect the submitted data).
>>
>> put "data.txt" into vfile
>> open file vfile for utf8 text update
>> put $_POST[firstname] & comma & $_POST[lastname] & comma & $_POST[country] &  the time & return into vdata
>> write vdata to file vfile at end
>> close file vfile
>>
>> Data is getting saved, but in gibberish, not in kanji/utf8.
>>
>> Anyone see what I'm doing wrong?
>>
>> TIA
>>
>> Tim Selander
>> Tokyo, Japan
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Writing a UTF8 text file to server -- solved

Bob Sneidar via use-livecode
Just for posterity...

Tried many combinations of various commands.... opening the file
as a binfile instead of a text file solved my problem

Changed:
open file vfile for utf8 text update

To:
open file vfile for binary update

At which point the same command:
write vdata to file vfile at end

properly saved the data as utf8/kanji to the file on the server.

All's well that ends well.

Tim Selander
Tokyo, Japan



On 2018.10.04 15:48, Tim Selander via use-livecode wrote:

> Hi Scott,
>
> Added info; I have <?lc put header "Content-Type: text/html;
> charset=UTF-8" ?> at the top of the web page source.
>
> Then, I only found outputTextEncoding in the dictionary. It said
> it only works with CGI (server), put when I put:
> set the outputTextEncoding to "utf-8"
>
> into the script before dealing with the $_POST array, it broke
> the Kanji on the web page itself.
>
> Googling turned up info on the textEncode function, but this
> script still results with a saved file of gibberish and not Kanji.
>
> Changed the script to this:
> put $_POST[firstname]      --(Results in Kanji name to web page)
> put "data.txt" into vfile
> open file vfile for utf8 text update
> put textEncode($_POST[firstname], "UTF-8") into vdata
> write vdata to file vfile at end
> close file vfile
>
> but still get a file with broken kanji.
>
> Any hints?
>
> Tim
>
>
>
>
> On 2018/10/04 15:08, scott--- via use-livecode wrote:
>> Hello Tim,
>>
>> Did you look at the textEncode function?
>>
>> —
>> Scott Morrow
>>
>>> On Oct 3, 2018, at 10:22 PM, Tim Selander via use-livecode
>>> <[hidden email]> wrote:
>>>
>>> I am using Livecode Server on Livecode's hosting plan.
>>>
>>> Taking my first stab at a web response form. I am getting the
>>> data from $_POST fine, and when I simply do something like:
>>> put $_POST[firstname]
>>>
>>> the UTF8/Kanji word shows up fine in the webpage. But I am
>>> unable to save the data to a file on the server encoded in
>>> UTF8 (simply trying to collect the submitted data).
>>>
>>> put "data.txt" into vfile
>>> open file vfile for utf8 text update
>>> put $_POST[firstname] & comma & $_POST[lastname] & comma &
>>> $_POST[country] &  the time & return into vdata
>>> write vdata to file vfile at end
>>> close file vfile
>>>
>>> Data is getting saved, but in gibberish, not in kanji/utf8.
>>>
>>> Anyone see what I'm doing wrong?
>>>
>>> TIA
>>>
>>> Tim Selander
>>> Tokyo, Japan
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage
>>> your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode