Since your ExeOutput for PHP application runs on Windows, you may want to save files locally. In some cases, this involves asking the user for a path and filename.
The “Save As” dialog box lets the user specify the drive, directory, and name for the file to be saved.
It can be invoked with the SaveFileDialog HEScript command. This topic explains the steps to implement a “Save As” dialog box in your PHP application.
Step 1: Create the HEScript #
-
Paste the following code into it:
function SaveDlgFile: String; begin // Ask for filename. Result := SaveFileDialog("Save Text As", "*.txt", "*.txt", "Text Files (*.txt)|*.txt|All files (*.*)|*.*", ""); // Returns a blank string if the user cancels. end;
This code calls the built-in SaveFileDialog HEScript command, 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, or an empty string if the dialog is canceled.
- 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 "Save As" dialog...
$filename = exo_return_hescriptcom("UserMain.SaveDlgFile", "Error");
echo "Filename: " . $filename;
if (empty($filename)) {
echo "Operation canceled.<br>";
return;
}
// Example of saving a PDF file from a library like FPDF.
$pdf->Output($filename, "F");
echo "Done.";
?>
Warning
Virtual files (in the Data subfolder) will not appear in the “Save As” dialog box unless you activate the Do not hide virtual files in open/save dialog boxes security option.
How to Create and Save Files with PHP
Selecting Files with PHP in Local Applications (Upload Replacement)