Applications created with ExeOutput for PHP are not designed to function like a web server. You may need to adjust your PHP code to create or access files on the user’s computer, or files compiled into your application’s EXE file, which are listed in the File Manager.
Tip
Please refer to the Accessing Files topic of the General Demonstration for live demonstrations and further explanations about working with local files from your ExeOutput for PHP apps.
Accessing Local Files #
By default, PHP scripts in your application can access any local file on the user’s computer. Absolute paths should be used. See below for how to access files shipped with your application or compiled into it.
Accessing Source Files from the Internal Browser #
Your application functions as if it were server software, serving webpages and related files through the HTTP protocol. When the application runs, it creates a custom pluggable protocol (similar to HTTP, FTP, etc.) to communicate with the Chromium rendering engine. In other words, the application works like a small server combined with a client (the main window that allows users to navigate HTML and PHP pages). Your website is then available as if it were on a server, but without requiring an internet connection or a physical server.
Tip
The internal browser can read files from the storage location only if URLs begin with the base URL followed by the virtual path to the file.
The base URL depends on the selected rendering engine:
- For the CEF engine, the base URL is
https://heserver/. - For the WebView2 engine, the base URL is
https://heserver.example/to ensure proper cookie handling.
For instance, to access a page named index.html with the CEF engine, you would use the URL https://heserver/index.html.
When your application starts, the browser automatically navigates to your index page.
Accessing External Files from the Internal Browser #
Your application can automatically load external resource files (not compiled into the EXE). For instance, you can keep image and media files outside the EXE file (in the same folder or a subfolder).
Examples:
If an HTML file references
image1.png, the application will look for theimage1.pngfile in its compiled data. If not found, it will try to locate and load it from the same folder as the EXE file (depending on the URI).If you have an image file in a subfolder, e.g.,
<img src="myfolder/my image.png" />, the application will expect the “my image.png” file to be in a subfolder named “myfolder” (if you leave the file external).
Note
External files must be deployed with the application’s EXE file in their respective folders.
Accessing Source Files from PHP #
ExeOutput for PHP leads the PHP runtime to believe that PHP scripts and other compiled files are on the hard disk in a Data subfolder, when they are actually held in virtual memory.
For instance, if the path to your EXE file is E:\my folder\myprogram.exe, the path to the “Data” subfolder will be E:\my folder\data.
You can think of the Data subfolder as playing the same role as the www folder in Apache.
Tip
The DOCUMENT_ROOT server variable contains the full path to the virtual Data folder.
Info
You can also keep PHP files outside the EXE and place them directly into a physical Data subfolder (see below).
For security reasons, you may want to choose a custom name for the virtual Data folder. The ExeOutput for PHP virtualization engine allows you to choose any virtual folder, even one on a non-existent drive. To activate this feature, go to “PHP Settings” => “Main Settings” and enable “Use an absolute path for the virtual “Data” subfolder“. Then, enter the path of your choice, for instance, X:\Data.
Troubleshooting “file missing” Errors #
Generally, ExeOutput for PHP intercepts all files requested by the PHP runtime and makes them available. For instance, ExeOutput for PHP supports include, require, include_once, and require_once.
Warning
PHP’s fopen function cannot download and open files from URLs beginning with http://heserver/, as no real web server is used.
If PHP displays “missing file” errors or warnings such as “php failed to open stream“, you may need to mark files in the File Manager (select your files, click File Properties, and turn on the Unpack the file(s) to virtual memory at startup option) or use the ExeOutput-specific PHP function named exeoutput_unpackvirtualfile.
string exo_unpackvirtualfile ( string $sourcepath , string $optionaldestpath )$sourcepathis the virtual source path to the compiled file you want to unpack to memory.$optionaldestpathis the absolute path to the destination virtual file. If you leave it blank, the path is constructed from$_SERVER['DOCUMENT_ROOT']and the virtual path.
The function returns the absolute path to the virtual file in UTF-8 format. This path can be used with PHP functions like fopen, file_exists, and file_get_contents.
Example: The following script makes demo1.pdf available and displays its full (virtual) path and size:
<?php
$filename = exo_unpackvirtualfile('res\demo1.pdf', '');
echo $filename . ': ' . filesize($filename) . ' bytes';
?>Accessing External Files from PHP Scripts #
You can create a physical Data subfolder to place any external or resource files that your application or PHP scripts require, such as database files, XML, etc. Even PHP files can be placed in this folder and used in conjunction with the PHP scripts compiled into your application.
We recommend using the “External Files” feature of ExeOutput for PHP to manage external files automatically.
Important
External files must be deployed with the application’s EXE file in the Data subfolder.
Warning
If the “Use an absolute path for the virtual “Data” subfolder” option (“PHP Settings” => “Main Settings”) is enabled, you will not be able to access real files that you may have placed in a physical Data subfolder.
For instance, if you have a file named include1.txt in the Data folder, the following script will display its contents:
<?php
$cont = file_get_contents($_SERVER['DOCUMENT_ROOT'].'\\include1.txt', FILE_USE_INCLUDE_PATH);
print($cont);
?>About is_file and is_dir #
The standard PHP functions is_file and is_dir have been modified to handle virtual files and folders. They will return true if you check for the existence of a virtual file (even if it is not yet in memory) or a virtual folder.