Web design software - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY As
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY As you can see from the screenshot on the previous page, the folder doesn t contain only images, so it s necessary to extract them before you can build a drop-down menu. First let s take a look at how to do the same thing in PHP 4. Opening a directory to inspect its contents If your server is still running PHP 4, complain to your hosting company (PHP 5 has been a stable release since July 2004), and in the meantime do things the old way. Inspecting a directory is similar to opening a file for reading or writing. It involves the following three steps: 1. Open the directory with opendir(). 2. Read the directory s contents with readdir(). 3. Close the directory with closedir(). So, instead of the single line of code required in PHP 5 or later, you need this (the code is in opendir.php in the download files): // open the directory $folder = opendir(’../images’); // initialize an array to store the contents $files = array(); // loop through the directory while (false !== ($item = readdir($folder))) { $files[] = $item; } // close it closedir($folder); The readdir() function gets one item at a time and uses an internal pointer in the same way as the functions used with fopen(). To build a list of the directory s entire contents, you need to use a while loop and store each result in an array. The condition for the loop is contained in the following line: while (false !== ($item = readdir($folder))) { The readdir() function returns false when it can find no more items, so to prevent the loop from coming to a premature end if it encounters an item named 0, for example, you need to use false with the nonidentical operator (!==). Of course, it s unlikely you ll intentionally name an item 0. However, good programmers expect the unexpected. This makes absolutely sure the function works as intended. Each time the while loop runs, $item stores the name of the next file or folder, which is then added to the $files array. Using this trio of functions isn t difficult, but the one-line scandir() is much simpler.
You want to have a cheap webhost for your apache application, then check apache web hosting services.