How to keep files external in a PHP app

You are going to learn how you can keep files external (outside the application EXE file) in a PHP app.

Large source files like audio and video files can be kept outside of the PHP application made with ExeOutput for PHP, so their loading time is highly decreased. In fact, all files that were first compiled in the application .exe must be unpacked in memory in order to be accessible by the application. Then, this unpacking step requires time, especially for very large files.

To reduce this loading time, you can leave your files outside the EXE file, because applications made with ExeOutput for PHP can also load files from the local file system automatically.

External files must be deployed with the application .exe file, so do not forget them when you distribute your application. Moreover, you can also pack them into an installer with Paquet Builder or zip them into a Self-Extracting archive.

Exclude files from being compiled into the EXE

To keep a file (to be normally compiled inside the application) as external, it’s easy: select it in the File Manager and click Properties.

File Properties

The “File Properties” window is displayed; tick “Exclude the selected file(s) from the application” and validate with OK.

Exclude File To Keep It External

Finally, rebuild your application. The excluded files are no more compiled into the .EXE.

Making external files accessible to the application

Now that our files are excluded, they still have to be accessible to our application. This is possible by placing these external files in a particular subdirectory called “Data“.

The path to this “Data” directory must be the same as the one to access the EXE file of the PHP application.

Let’s take a look at it in pictures:

Data Subfolder

Open Windows Explorer and browse to the directory where your application’s EXE file is located. After that, create a subdirectory that you name “Data” and place all files external to your application in it.

That’s all. From now on, your application will be able to read external files directly when they are requested either by PHP or by the Chromium rendering engine.

How to access external files in HTML?

Everything now happens as if the external files were accessible at the root of the application’s internal storage.

For example, we have placed the image file “arc.jpg” in the subdirectory “Data”:

In order to be able to read it in an HTML page at the root, it is sufficient to use the following HTML code:

<img src="arc.jpg" />

And it works as expected. Indeed, when the application is launched to display the HTML page in question, the image is automatically found, although it is external to the application:

How to access external files in PHP?

Similarly, PHP is perfectly capable of accessing external files using the global to obtain the absolute path to the “Data” subdirectory.

Here is a simple PHP code that allows you to read the content of a text file external to the application located in the Data directory:


$cont = file_get_contents($_SERVER['DOCUMENT_ROOT'].'\\include1.txt', FILE_USE_INCLUDE_PATH);



And how do I read a file that is in the same directory as the EXE file?

Just add ..\\ in the relative path of your file. For example, here is the same code as above but which will read a text file that is in the same directory as the EXE file of the application:


$cont = file_get_contents($_SERVER['DOCUMENT_ROOT'].'\\..\\include2.txt', FILE_USE_INCLUDE_PATH);