I am using Ubuntu as my OS, and I have XAMPP in it. In the htdocs
folder, I have created a project folder in which I have index.php
file. Now inside the index.php, a part of the code does this:
fopen("colors_new.csv", "w");
From the manual,
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
But instead of the file being created, I am getting
Warning: fopen(colors_new.csv): failed to open stream: Permission denied...
And when I look into the project folder, the colors_new.csv
file is NOT created.
When I run this program in another computer running Windows OS, it runs successfully. The file is successfully created.
How do I fix this problem in Ubuntu?
WHAT I TRIED:
I tried to run sudo chmod 777 colors_new.csv
but I get chmod: can not access colors_new.csv. No such file or directory.
. I tried this with just the file name (as shown) while the terminal WAS in the project directory; as well as by giving the full absolute path of the file. Got the same error both times.
NOTE: I have seen other questions, and as indicated above, I tried to give permissions to the file. The other questions did not solve the problem, the accepted answer below did solve it.