File I/O Handling
Filesystem operations are some of the most important in programming. We can enumerate session data storage in PHP; user-uploaded files, generated report files, cached data, logs – all of them utilize the filesystem. Of course, there are many other alternatives for persistent storage, but knowing how to operate the filesystem in a language is especially important due to its availability. It is basically present anywhere and can be used immediately.
Working with the filesystem, sometimes, you might want to read or write into a file that is stored in a known location relative to the script file location. For example, for a script that is created in the /app/demo/
directory that wants to read files from source/
relative to its location (in other words, /app/demo/source/
), it would be better to know the script location.
This is different to the current working directory, because you may run the script from other locations as well. For example, if the current...