You need to give it the path where you want it stored. You are telling it to write in the document root.
file_put_contents(filename, data, mode, context)
https://www.w3schools.com/php/func_filesystem_file_put_contents.asp
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using Laravel 8, and I'm working on an automation system that uses Dusk in a controller.
At some point i want to take a screenshot:
$browser->visit('http://myapp.com')
->screenshot('test');
But i get this error:
file_put_contents(/test.png): Failed to open stream: Read-only file system
I tried to change the permissions of /storage as well as the permissions of /tests/Browser/screenshots (because i am not really sure where the screenshots will be saved, and i don't really mind as this is just a test to investigate an unexpected behavior - I only need to see those screenshots a few times).
I tried:
php artisan cache:clear
php artisan view:cache
chmod -R 775 storage/
chmod -R 775 tests/Browser/screenshots
Still the same error. What am i missing? Thank you!
Please or to participate in this conversation.