Search code examples
phpamazon-web-servicesamazon-s3flysystem

Include/require file from Flysystem


My PHP application dynamically generates some script files that are later run by using require or include.

I'm now in the process of migrating my production server to Amazon Web Services, to get scaling and load balancing. This means that the generated script files should no longer be stored in the local file system, but rather in an S3 bucket.

Therefore I would like to use Flysystem, so I don't have to think about whether the files are stored locally (development) or in an S3 bucket (production).

But how do I require or include a file from Flysystem? Do I have to get the file content and then eval it?


Solution

  • It is not possible to include or require a file directly from Flysystem. A workaround is to get the content of the file and eval it. Note that you must handle any leading <?php and trailing ?> tags in the evaled file.