Forums | Mahara Community

Developers /
Pieforms or. json_repy problem


Gregor Anželj's profile picture
Posts: 349

21 December 2009, 9:37

I get a response from web service. The response is a valid  MS Word (or OpenDocument or PDF or XML file). I would like to "pass" this response = file to user, so he/she could save this file to his/her computer. I've done that with following lines:

header('Content-type: application/msword');
header('Content-Disposition: attachment; filename=cv.doc');

but  then the statement

$form->json_reply(PIEFORM_OK,  'some string'); 

doesn't get executed (I think?!?). So on the left upper corner it says "Loading..." and the Submit button has a label "Processing..."

What should I do, to make this function to finish or to make these labels to disapear?

Help, please!

anonymous profile picture
Account deleted
Posts: 808

21 December 2009, 17:36

Hi Gregor,

I'd try calling the serve_file() function from htdocs/lib/file.php which will set those headers for you, and also make sure your pieform submit function calls $form->reply(PIEFORM_OK, 'some string').

You might also want to look at the code that serves up the export file (htdocs/export/index.php, htdocs/export/download.php).  It's probably a bit more elaborate than you need (it displays a progress bar in an iframe) but it will give you an idea.

Gregor Anželj's profile picture
Posts: 349

22 December 2009, 5:54

I looked at mentioned files, but they assume that you first have to create file on server and then serve it - or maybe am I missing sometnihg?

I want to send the data in an XML form to Europass Web service to get Europass CV or Language portfolio as file - then I want to serve that file instantly (I don't want to write it on server's disk). Is it possible with serve_file() function?

anonymous profile picture
Account deleted
Posts: 808

22 December 2009, 17:19

Yeah, you're right, it's no good for what you're trying to do, there's a whole lot of stuff in there that assumes it's a file on the filesystem.  I don't know of any code that does what you're trying to do exactly.  But I suspect it will work okay if you use the same approach as in the export code, by serving up your headers and xml data from a separate script loaded in an iframe.

4 results