PHP – Dealing with files and directories

Today with Laravel PHP Framework, you still need to write PHP native code.

In the web, there are a lot of helpful programming packages that help each one of us from reinventing the wheel and testing a code that already tested by many other developers in the world, and you also get it for free…

For example, a one helpful PHP package is called Carbon (Carbon Website), that is perfect when you need to build some features that depend on date and time.

Nevertheless, you will still need to write your own code, that will do your job in a better way.

In this post, I will write some PHP methods that can help you dealing with files and directories in your “file system/filesystem” on your server.

1. getDirectorySeparator

This tiny code helped me in real production servers, where you don’t know how the slash is used in the server operating system(OS), because you may deploy your code to server of windows OS or Unix, and each one of this has different slash, so it may be like \ or /

2. isPathExistAndATypeOfFile

To check if specific path in your File System is exist and it is also a type of file, then this function may help you:

3. createDirectoryIfNotExists

If you have a full path of specific directory, and you want create a new one if it’s not existed in your filesystem.

Those are simple methods that I hope it will help you achieve your purpose.
Later this will be updated with other helpful methods to deal with files and directories.

Wish you the best…

mhmd

Hello, I'm Mohammad Daka, software engineer who love coding. In my spare time I blogs about JavaScript,PHP, Chrome Extensions, helpful resources and tools, I'm also working on my own projects. Don't hesitate to contact me at my twitter account: @mohammad_daka :)

You may also like...

1 Response

  1. backupbot says:

    If you have a full path of specific directory, and you want create a new one if it’s not existed in your filesystem.website backup

Leave a Reply

Your email address will not be published. Required fields are marked *