Delivering Files with lcServer ?

Martin Baxter mblivecode at harbourhosting.co.uk
Fri Apr 25 12:15:05 CEST 2014


On 25/04/14 10:32, Peter W A Wood wrote:
> Hi Scott
> 
> With a little help from Google, I have managed to put together this
> example of serving a file from LiveCode Server:
> 
> This is the html file from which you can request the download:
> 
> <html> <a href="webtest.lc">click here</a> </html>
> 
> and here is the LiveCode server page (webtest.lc)
> 
> <?lc
> put "test.zip" into tName           
> put url ("binfile:" & tName) into theFile
> put header "Content-Description: File Transfer"
> put header "Expires: 0"
> put header "Cache-Control: must-revalidate"
> put header "Pragma: public"
> put header "Content-Type: application/octet-stream"
> put header "Content-Disposition: attachment; filename=" & tName
> put header "Content-Transfer-Encoding: binary"
> put header "Content-Length:" && the length of theFile
> put binary theFile
> ?>
> 

> The biggest problem that I had was getting LiveCode to download a
working zip file until I added the "binary" to put. (I read to do that
in the release notes for LiveCode Server 4.6.3, thanks to Google).
> 
> Hope this helps.
> 
> Regards
> 
> Peter

Yes, that looks right,

I think that:

header("Content-Description: file Transfer");

Is the interesting part. IIRC that should prompt the browser to
recognise that this is a file download.

Then you just have an href= to the script that handles the download, in
the usual way, and when the link is clicked, the browser should
recognise the intent by inspection of the headers, and by default should
not attempt to change the page location.

Your download scipt might want to explicitly change the location in the
case of an error or something, however.

Martin



More information about the use-livecode mailing list