When run as a desktop application, PHP code can access local files on the user’s computer, making it possible to save and modify files locally. To learn how to load compiled files, please see this page.
Tip
Please refer to the Saving Files topic of the General Demonstration for live demonstrations and further explanations about saving local files with your ExeOutput for PHP apps.
Saving and Storing Files Locally #
PHP provides several ways to load and save files. To save files correctly, you must ensure that the user has write permissions for the desired location.
For instance, a portable application is often started from a USB stick, and the folder containing the EXE has write permissions. In this case, your application will be able to save files in that folder. Conversely, if your application is installed in the Program Files directory, it is generally not allowed to save files in its own folder due to the Windows User Account Control (UAC) feature.
To solve this, ExeOutput for PHP provides a dedicated storage folder for your application. The absolute path to this folder can be retrieved with the following PHP command:
<?php
$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
echo $storagelocation;
?>HEPubStorageLocation is a global variable defined by ExeOutput for PHP at runtime. The exo_getglobalvariable function is a built-in PHP command provided by ExeOutput for PHP.
Tip
This folder is always available and can be used to store your application’s settings. You can customize the name of this storage folder on the Output -> Output Settings page.
PHP Code: Saving a File with fopen / fwrite #
In compiled applications, you must pass absolute paths to the fopen PHP function.
<?php
$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
$file = $storagelocation . 'myfile1.txt';
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
?>Tip
If you want to let users choose the save path themselves, you can display a “Save As” dialog box.
Accessing Files in Compiled PHP Applications