Displaying a list of file stats

Usually after completing a long project I find that I’ve created various extraneous files in the project directory; like zip files or maybe a few big graphic files or some huge MySQL dumps. If the directory sizes are small I can manually delete those unwanted files. But if the directory sizes are big or if they are nested deeply, than it can be quite time consuming. Maybe you left a couple of huge MySQL dumps somewhere and forgot to delete them, thus increasing the project file size. And if you are trying to do the cleanup on a online server then it can be even more painful.

Or maybe you are just curious to find how various types of files are taking up your directory space.

Whatever the reason, below is a small php script that displays the distribution of files in a particular directory and its sub-directories by its type. This can be handy if you would like to see which files are taking up space in your project. Although you can easily do such kind of things with a variety of desktop tools, the following code can easily be used online, or integrated into your existing php application.
(more…)

Read More

Search & replace in files using php

Searching and replacing content in files is a common task all of us do regularly. Most programmers will implement it using Perl a shell script or through a editor. Perl offers itself as an excellent tool for the required purpose; we PHP programmers are not quite so lucky in that matter. Search/replace is easier from a shell prompt or an editor, but what if you have to do the same programatically in php. File_SearchReplace is a pear package that helps you search/replace in files through a nice object oriented interface.
(more…)

Read More