+ 28

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?

21st Mar 2020, 12:57 PM
Dual Core
Dual Core - avatar
4 ответов
+ 24
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!
21st Mar 2020, 1:21 PM
Dual Core
Dual Core - avatar
+ 6
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 🙂
23rd Mar 2020, 5:06 PM
DILA
DILA - avatar
+ 5
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 🙏
21st Mar 2020, 1:10 PM
Alfred Juma
Alfred Juma - avatar
+ 3
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.
21st Mar 2020, 1:06 PM
Gordon
Gordon - avatar