Rant on my favourite topics : LC server with a side-dish of on-rev :-)

Alex Tweedly alex at tweedly.net
Fri Nov 17 18:53:01 EST 2017

This is a bit of a rant, so if you're not in the mood, switch off now :-)

I will (when I've calmed down and organised myself :-) submit bug reports.

So, normally, I don't have much time for my favourite hobby of scripting 
in LC, which lately has been mostly LCServer for a couple of simple 
websites I have built for friends. But this week I had lots of time set 
aside, because I've (finally) convinced one of those website owners to 
do her own maintenance / updating of the site.

The site has many images - which I have typically put into my desktop 
copy of the site, tried them out - and then synch'ed those up to the 
real site. However, for the site owner to upload photos, I needed to 
revive my script for uploading files (specifically images), which hasn't 
been used in a while. And indeed, may have been played around with in 
the meantime - so I can't be sure that this is exactly a "once-working" 

It was written a long time ago - back before there was any built-in way 
to parse multi-part form content - so I did my own parsing of the POSTed 
data (actually, I think someone else did it first, and I copied that :-)

However - that no longer works. Using $_POST_RAW fails when the uploaded 
file is a jpg image - it works ok for text file, simple PNGs etc. - but 
fails dramatically when the file is proper binary. Test script of

> <?lc
> set the errormode to inline
> put "raw has" && the number of bytes in $_POST_RAW && "bytes<br>"
> ?>
fails with

file "/home/ua886128/public_html/tweedly.co.uk/tryme.lc"
   row 3, col 18: Chunk: can't get source string
   row 3, col 18: Chunk: error in chunk expression

when the POSTed data includes a JPG file.

While google'ing around for that, I ran into the Livecode lesson on this 


which uses the (newer) $_FILES array which does the complex parsing of 
the file info from the form - a big improvement !! And indeed, the 
example there works does work. BUT - it seems that although it correctly 
parses out the file information, it loses any other POSTed values. So if 
your form consists *ONLY* of one or more files to upload - you're good. 
But if you pass any other values (e.g. folder you want it to go to, 
meta-info, passwords, etc.) that is all lost. Which basically means it's 
unusable for any real scenario.

I hear you asking - which version ?   :-)

Well, it's on my on-rev account - so it's version 7.1.0 !! - pretty old 
and out of date.

Off to check the on-rev documents - which claim that the default version 
will be the latest released version. Nope!

Another google - how do I use a different version on on-rev ? Well, 
there's a "lesson" for that too ( 

Summary of Answer : use .htaccess, and specify the exact version I wish 
to use; engines are stored in /cgi-bin/livecode-server-<version_number>

Hmmm - which ones are available ?

Turns out that /cgi-bin is read-protected (probably sensibly :-) - which 
means there is no way to find out what ones there are. I tried a few 
guesses, but didn't stumble into one - so unable to use on-rev.

Fortunately, I have another account somewhere else :-)

So - moved everything over to my HostM account (running 8.1.7), and with 
this later version the $_FILES and $_POST arrays are both properly 
available. Hurrah !   ($_POST_RAW still causes complete failure).

So - only 3 days later, I have finally got past a problem that shouldn't 
even have existed - just occasionally I with I'd stuck with PHP :-)

But - still need to solve the problem of my database interactions - 
which I want to do through revIgniter, rather than through my little 
utility script for doing the actual upload. No problem - just take the 
rest of the data, stick in a JSON-encoded cookie, and redirect back to 
the revIgniter script on success.

That's when I ran into the problem that aArrayToJSON() isn't 
(automatically) available on LCServer. Fortunately Devin has given me an 
answer to that (Thanks!!) so I should be back on track in another hour 
or two ...

End of rant. Thanks for listening :-)


More information about the use-livecode mailing list