How and where do I work with files in PHP?

I learnt fopen(), fwrite() and fclose() to work with files in PHP. It's nice but I don't understand where those files are. Can they be located on a server or a client or both?


3/21/2020 12:57:33 PM

Dual Core

4 Answers

New Answer


Wow! That was quick. Than you guys for your answers. You are awesome people. I know this sounds silly but I want to clarify that none of those functions mess with files on a local machine. Happy coding!


PHP is a languge used to perform programming in servers. So all the work you are doing there are based on servers. (Think you know what is a server and how servers work/behave). Any program you run with PHP doesn't work on the client's computer. Everything is done in the server. So the final decision : When you create and work with files, its all done in the server. When you are working on your local machine, use xampp server. You will notice all of those concepts clearly. (in the htdocs folder (default)) Happy coding 🙂


You need to have a file eg a text file (file.txt) to work on using the methods. Eg, when you have a text file in the same location where your php file is, you can use this syntax to open the file; <?php $handle=fopen("file.txt","a"); Then wrtting data to it, lets say we are getting values from a login page to be written to the file Foreach($_GETas $variable=>$value) { fwrite ($handle, $variable); fwrite ($handle, "="); fwrite ($handle, $value); fwrite ($handle, "\r\n" } fwrite ($handle, "\r\n"); exit; ?> But first you need a local server installed I hope this helps Happy coding 😊 Keep coding 🙏


Installing Local Server for PHP tutorial: https://youtu.be/mXdpCRgR-xE PHP is server-side script, you can practice after setting up a local server.