php-wasm icon indicating copy to clipboard operation
php-wasm copied to clipboard

Add example to include/require file

Open vrana opened this issue 9 months ago • 3 comments

I've read through the examples at Php-Wasm in Javascript and Php-Wasm in Static HTML and I haven't found an example of how to include / require / include_once / require_once another PHP file. My use-case is pretty simple. I have a PHP file with a function and I want to use it from JS. I've tried many different options but all of them failed, usually with this error:

Warning: PHP Request Startup: Failed opening 'phpShrink.php' for inclusion (include_path='.:') in php-wasm run script on line 2

Am I missing something obvious?

vrana avatar Mar 15 '25 11:03 vrana

@vrana You should be able to include any additional PHP files under the files constructor parameter, which is available under static HTML as the data-files attribute. Once they're in the FS you should be able to include then normally.

https://php-wasm.seanmorr.is/filesystem/loading-files.html

https://php-wasm.seanmorr.is/getting-started/php-in-static-html.html

seanmorris avatar Apr 10 '25 22:04 seanmorris

Thank you. It seems that this was simply a version problem. I've imported https://cdn.jsdelivr.net/npm/php-wasm/PhpWeb.mjs but you need to import https://cdn.jsdelivr.net/npm/[email protected]/PhpWeb.mjs. Can you please add this to https://php-wasm.seanmorr.is/filesystem/loading-files.html?

vrana avatar Apr 12 '25 19:04 vrana

Anyone else facing this issue and want it to run offline, You can see simple code here in the repo https://github.com/coolb0y/php-inbrowser/tree/php-browser

coolb0y avatar Apr 19 '25 17:04 coolb0y