PHP SOLUTIONS: DYNAMIC WEB DESIGN (Post office web site) MADE EASY 8.
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY 8. There s just one final refinement we need to make. The code in random_image.php and in step 6 prevents errors if the selected image can t be found, but we ve left the most important section of the code completely devoid of similar checks. Temporarily change the name of one of the images, either in random_image.php or in your images folder. Reload index.php several times. Eventually, you should see an error message like the following, making your site look very unprofessional. 9. The conditional statement at the foot of random_image.php sets $imageSize only if the selected image both exists and is readable, so if $imageSize has been set, you know it s all systems go. Add the opening and closing blocks of a conditional statement around the
Images that exist will display normally, but you ll avoid any embarrassing error messages in case of a missing or corrupt file a much more professional look. Don t forget to restore the name of the image you changed in the previous step. You can check your code against index05.php and random_image02.php. Preventing errors when an include file is missing A danger with using includes is that the include file may be corrupted or accidentally deleted from the server. Or you might type the filename or pathname incorrectly. Figure 4-11 shows what happened when I mistyped the name of random_image.php. It s not a pretty sight. Figure 4-11. Unless you take preventive measures, a missing include file results in ugly error messages.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.