Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Annaro's avatar

file_put_contents: Failed to open stream: Read-only file system

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!

0 likes
4 replies
Annaro's avatar

@Tray2 Hi there! Thank you for your answer, that i only just saw... The thing is, i am not calling file_put_contents myself, I am calling $browser->screenshot(name_of_my_jpg_file') and Dusk "decides" where my screenshots are saved. I am kinda expecting it would be an appropriate directory. I know i can configure that directory, but i can't find where anymore... I tried to pass the path with the file name as an argument, but failed miserably as i get

mkdir(): Read-only file system

which shows i am not passing the path like i should, if i am actually still at the root. Or that i am already in an appropriate directory and don't need to add the path? Not sure...

Annaro's avatar

@Tray2 Thanks for taking the time to help, and for confirming the directory. I am not sure if the screenshots are actually meant to be saved in that directory in my case, because it seems like the folder has the right permissions, but it still fails:

ls -ld ./tests/Browser/screenshots
drwxrwxr-x  3 adrien  staff  96 25 Dec 16:57 ./tests/Browser/screenshots

but file_put_contents(/test.png): Failed to open stream: Read-only file system

I did not modify the path (for screenshots) in dusk/src/Console/DuskCommand.php and dusk/src/TestCase.php, but i am using Dusk in a controller (as a bot) and not for actual tests, so i am not sure if it might have changed the directory for screenshots. How could i check this? Thank you so much!

Please or to participate in this conversation.