Skip to content

Selecting files with PHP scripts with Open Dialog box - Upload replacement

Your application made with ExeOutput for PHP may need to work with local files. Since you can access local files directly with PHP, upload functions are not really necessary. In fact, your application is not designed to work on a web server: users do not have to upload their local files to a remote server if you want to process them with the PHP code of your application.

This topic shows you how you can ask the end user to select a file, and then process it with PHP.


Of course, ExeOutput for PHP also supports tradional file upload. You can see the General Demonstration for live demonstrations and further explanation about uploading files with your ExeOutput for PHP apps.

Asking the end user with an Open File dialog box

When an end user has to upload a file, the browser asks you to select it with an Open dialog box. You can achieve the same goal with an application made with ExeOutput for PHP.

The Open dialog box lets the user specify the drive, directory, and the name of a file or set of files to open.

It can be invoked with the HEScript command named OpenFileDialog.

Step 1: create the HEScript script

Open the UserMain script in ExeOutput for PHP.

And paste the following HEScript code:

function OpenDlgFile: String;
Result := OpenFileDialog("Select a File to open", "*.*", "*.*", "All files (*.*)|*.*", "");

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

function OpenFileDialog(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

echo "Asking for filename...<br>";
// Executes HEScript to call the system dialog "Open"...
$filename = exo_return_hescriptcom("UserMain.OpenDlgFile", "Error");

// The $filename variable contains the full path to the file selected by the user. It can be passed to fopen  
// for instance.

if (empty($filename))
echo "You have not selected any file. Operation canceled<br>";




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

Accessing Files in Compiled PHP Applications

How compiled PHP applications work