Ask coding questions

← Back to all posts
Read-Only Filesystem Error in PHP
JohnjiRomanji (3)

I’m getting the following error in when running some web server php:

failed to open stream: Read-only filesystem

The lines I have narrowed it down to are:

$file = fopen($_POST["slug"]."/index.html", "w");
echo fwrite($file, "<!DOCTYPE html><html><head><title>URL Shortener ig</title><meta charset='UTF-8'></head><body><script>window.location=".$_POST["url"]."</script></body>");

Basically it needs to write to a html file to make a redirect for a specific slug on a url shortener.
This is my first php project.

From what I understand it is because the computer is protecting its files, but how can I fix this on replit? Is there a shell command or something?

Any help would be appreciated, thanks.

Answered by Coder100 (18109) [earned 5 cycles]
View Answer
Coder100 (18109)

The actual repl is inside a folder named your repl name.

so don't forget to add __dirname or whatever the equivalent is in php.