By: John Hanney Introduction In this example, we'll demonstrate a little more of the PHP code that helps make a Web page dynamic. Although the code on this page may not be considered advanced, it's definitely above what a beginner should be handling. Before you continue, be sure you've become familiar with HTML and PHP basics, and have read through our previous introductory page entitled "Using PHP". In addition, this example is presented with the assumption that DRH Internet is hosting your site. So if your site is not on a host with a similar layout and operating system, you may find you'll have to make some changes in order for the PHP code to work for you. Creating A Disk Space & FTP Status Page Here's something interesting to try from your site. Let's create a page that shows you how much disk space your site is using, and how many files are sitting in your FTP upload area. The first step is to create a simple HTML page that will be our shell for the final design.  We'll call it "disk_and_ftp_status.html":
Next, let us see what that page looks like without making any changes or adding any code:
Not much to it, huh? Now we've got to add some PHP code to make those numbers reflect the actual status of our site. So, let's replace the numbers with PHP code and make some minor cosmetic changes. We'll call it "disk_and_ftp_status.php".  Here's that new page:
At this point you could probably stop here, upload the new "disk_and_ftp_status.php" Web page, and give it a trial run. But stay with us as we briefly describe each of the highlighted areas and explain what's going on. We won't be getting too deep into the code. So if you wish, you may want to refer to an online PHP manual for direct answers to your coding questions. In figure three, on lines six and seven, we set a variable $myhome to the root path of the site and set $myFTPin to the default path of your incoming FTP area. These paths are typically the default for a DRH Internet account. Your paths may be slightly different if you're a visitor to our site, thus you would change them here. In the next section, we run the Linux command "du" and capture the total space from your root directory and all its subdirectories. We also strip out some unwanted characters, and insert commas to make the number look more presentable. The next two sections go together. Of course the captured space in bytes is displayed, but we also choose whether we want to display the word byte or the plural bytes by simply adding an "s". The next large section simply counts up all the files in you FTP area, ignoring the two "." and ".." directory entries. However, if you have a hidden file like .message, that will still be counted. And finally, the remaining sections just print out the results of the file count. We use that plural trick again to display is or are, and file or files. Conclusion Well that's it. We hope you at least pick up a few ideas by going over this supplemental coding example. Your next stop might be to visit some of the suggested sites on the prior page. Be sure to see some of their examples and check out some of the many forums available. |
|||||||||||||||||||||||||||