I’m trying to create txt file on fly using php fopen but unable to create it for unknown reason.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Just to add on what has already been mentioned, you can also check for any generated PHP
error_logfiles in the directory where the .txt file is supposed to be created. This might point in the right direction as well.
I’m sure the problem is with permissions. Apart from what Bobby has already mentioned I’ll recommend you to check the SELINUX of your Ubuntu.
You can check this tutorial for more information:
Want to learn more? Join the DigitalOcean Community!
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Sign up now
You would need to make sure that the Apache user has access to create files in your web root directory.
By default Apache runs as the
www-datauser so you could use:
sudo chown www-data /var/www/htmlto change the owner of the directory where you want to create your file at.
If this still does not work, I would recommend checking your Apache error log for mre infomration on why this is failing:
Let me know how it goes!