This topic is locked

why dont work this script in server of button ?

12/1/2019 12:22:47 PM
PHPRunner General questions
D
dirk author

I've created a custom button for a file to download.

But the script does not work.

If you run it through your own php file it works well.

What's wrong with this .....



$filename = "database_bel.gpx";
$ctype="application/force-download";
header("Pragma: public"); // required

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: private",false); // required for certain browsers

header("Content-Type: $ctype");

// change, added quotes to allow spaces in filenames, by Rajkumar Singh

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );

header("Content-Transfer-Encoding: binary");

header("Content-Length: ".filesize($filename));

readfile("$filename");

exit();
Sergey Kornilov admin 12/1/2019

Server part of button's code is executed via AJAX. You cannot output anything there, you cannot change headers there.
What you can do is to pass the file name from Server event to ClientAfter event to send file to download from ClientAfter event. For the full undertanding of how things work this article is must read:

https://xlinesoft.com/phprunner/docs/tri-part_events.htm