Send a file to a browser
Posted: Tue Oct 08, 2013 9:47 pm
I am trying to figure out the Livecode equivalent of this PHP:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
I have everything figured out except what the livecode equivalent of the read statement is.
Basically I have a server script that accepts an upload from the user, does a bunch of processing, then creates, on the server, a zip file with three items in it. at the end of the processing I want the server to send that zip file to the user's browser for the user to download.
Previously, the result of the processing was just a csv file, which is sent to the browser with
put header "Content-dispostion: attachment; filename=mycsvfile.csv"
put header "content-Type: text/plain"
put mycsv ---a variable containing the csv data as text
But, because of changes I made to the application I now have three related files that I want to return and putting them in a zip file made the most sense, esp. since one of them is a 30 meg text file, and sending that.
I am sure that what I want to do is pretty simple, I just can't seem to figure out the right livecode to do it, and the closest thing I could find was the PHP above.
I tried using
put url "binfile:" & thePathToMyZipFile
in place of the readfile statement, but no luck. I do get a downloaded file, but it's far to small, and it's an unreadable zip file.
The code I tried was:
put header "Content-dispostion: attachment; filename=" & theNameofMyZipFile --this is just the name and extension, not the full path
put header "content-Type: application/plain"
put url "binfile:" & thePathToMyZipFile --this is the relative path & filename i.e. ziptemp/myzipfile.zip
I am sure that what I want is something along these lines - I am probably doing something dumb regarding encoding or something....
edit - oh, and I have verified that the zip file is actually being created on the server, and it is, and it's a valid zip file with the information I want in it.
Thanks!
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
I have everything figured out except what the livecode equivalent of the read statement is.
Basically I have a server script that accepts an upload from the user, does a bunch of processing, then creates, on the server, a zip file with three items in it. at the end of the processing I want the server to send that zip file to the user's browser for the user to download.
Previously, the result of the processing was just a csv file, which is sent to the browser with
put header "Content-dispostion: attachment; filename=mycsvfile.csv"
put header "content-Type: text/plain"
put mycsv ---a variable containing the csv data as text
But, because of changes I made to the application I now have three related files that I want to return and putting them in a zip file made the most sense, esp. since one of them is a 30 meg text file, and sending that.
I am sure that what I want to do is pretty simple, I just can't seem to figure out the right livecode to do it, and the closest thing I could find was the PHP above.
I tried using
put url "binfile:" & thePathToMyZipFile
in place of the readfile statement, but no luck. I do get a downloaded file, but it's far to small, and it's an unreadable zip file.
The code I tried was:
put header "Content-dispostion: attachment; filename=" & theNameofMyZipFile --this is just the name and extension, not the full path
put header "content-Type: application/plain"
put url "binfile:" & thePathToMyZipFile --this is the relative path & filename i.e. ziptemp/myzipfile.zip
I am sure that what I want is something along these lines - I am probably doing something dumb regarding encoding or something....
edit - oh, and I have verified that the zip file is actually being created on the server, and it is, and it's a valid zip file with the information I want in it.
Thanks!