This topic is locked

Using Page Designer to Add Button to Download a File

10/25/2018 8:12:55 PM
PHPRunner Tips and Tricks
L
lwthomas10 author

Using PHPRunner and Page Designer to Add button that will allow me to download a file from the Linux server.

Determined that file exists and that the filesize is correct.

Only the Server Button properties have PHP code as shown below:
--------------------------------------------------

$file = 'c:\users\lt5923\EPC_input.txt';
if (file_exists($file)) {

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

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

header('Expires: 0');

header('Cache-Control: must-revalidate');

header('Pragma: public');

header('Content-Length: ' . filesize($file));

readfile($file);

exit;

}

----------------------------------------
When I click the button the system hangs without downloading file or giving me option to Open/Save file.
Was expecting to download files using a button and the PHP code above.

C
carlos.oschi@gmail.com 11/29/2018

my friend, i do this simply using a command on javascript post event (after the php server)
location.href="filename";
it can be parametric using
php server code

$result['link'] = $data_link_variable;
and in javascript after
var link = result['link'];

location.href = link;
in some cases i need to build a file with some aditional issues like a interchange file, or a csv file, well i only change the link to a php file, and in the headers i use this
// previous process file...
file_put_contents($archivo, $datos); // the file created
header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename='.$archivo);

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

header('Expires: 0');

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

header('Pragma: public');
readfile($archivo);
its importan not make any echo or output aditional...
i hope this will be usefull.



Using PHPRunner and Page Designer to Add button that will allow me to download a file from the Linux server.

Determined that file exists and that the filesize is correct.

Only the Server Button properties have PHP code as shown below:
--------------------------------------------------

$file = 'c:\users\lt5923\EPC_input.txt';
if (file_exists($file)) {

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

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

header('Expires: 0');

header('Cache-Control: must-revalidate');

header('Pragma: public');

header('Content-Length: ' . filesize($file));

readfile($file);

exit;

}

----------------------------------------
When I click the button the system hangs without downloading file or giving me option to Open/Save file.
Was expecting to download files using a button and the PHP code above.