Skip to content

Save As Dialog Box in PHP applications

Since your PHP application compiled with ExeOutput for PHP is an application that runs on Windows, you may want to save files locally and in some cases, ask the end user for the path and filename of the file you want to create.

The Save As dialog box lets the user specify the drive, directory, and name of a file to save.

It can be invoked with the HEScript command named SaveFileDialog. The following topic tells you the steps to have a Save As dialog box in your PHP application.

Step 1: create the HEScript script

Open the UserMain script in ExeOutput for PHP.

And paste the following HEScript code:

function SaveDlgFile: String;
begin
 Asks for filename
Result := SaveFileDialog("Save Text As", "*.txt", "*.txt", "Text Files (*.txt)|*.txt|All files (*.*)|*.*", "");
 Returns blank string if user cancels the dialog.
end;

We call a built-in HEScript command named SaveFileDialog which is described in the Script Reference topic.

function SaveFileDialog(const aTitle, aFilename, aDefaultExt, aFilter, aInitialDir: String): String;

  • aTitle: title of the dialog box.

  • aFilename: default filename.

  • aDefaultExt: default extension.

  • aFilter: file extension filter

  • aInitialDir: initial directory

Result: returns the full path to the selected file. If canceled, returns an empty string.

Click Save Script. The HEScript function is now ready to be called from PHP or JavaScript.

Step 2: call from PHP

<?php 
echo "Asking for filename...<br>";

// Executes HEScript to call the system dialog "Save As"...
$filename = exo_return_hescriptcom("UserMain.SaveDlgFile", "Error");

echo "Filename: ".$filename;

if (empty($filename)) {
  echo "Operation canceled<br>";
  return;
}

$pdf->Output($filename, "F");

echo "Done.";

?>

Warning

Virtual files (in the Data subfolder) will not appear in the save dialog box, unless you activate the security option Do not hide virtual files in open/save dialog boxes.

How to create and save files with PHP

Selecting files with PHP scripts in local applications - Upload replacement

Accessing Files in Compiled PHP Applications