Cheap web hosting - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY What
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY What this chapter covers: Reading and writing files Listing the contents of a folder Automatically naming the next file in a series Opening remote data sources Creating a download link PHP has a huge range of functions designed to work with the server s file system, but finding the right one for the job isn t always easy. This chapter cuts through the tangle to show you some practical uses of these functions, such as reading and writing text files to store small amounts of information without a database. I ll also show you how to create a drop- down menu that lists all images in a folder, automatically name the next file in a series, and prompt a visitor to download an image or PDF file rather than open it in the browser. As with file uploads in the previous chapter, setting the correct permissions is crucial to success in using many of the file management functions. Unfortunately, hosting companies often impose limits on their use. So, I ll begin with a quick overview of some of the restrictions you need to be aware of. Checking that PHP has permission to open a file As you saw in Chapter 4, a PHP script has the ability to open another file and include the content as its own. In a default PHP configuration, the file doesn t even need to be on the same server; as long as PHP can find the file and open it, the contents of both files are merged. This is an extremely powerful concept, which sadly is open to misuse. As a result, you must have the right permissions to open a file. This affects not only the file system functions that are the main focus of this chapter, but also any function that opens another file, among them include(), require(), and simplexml_load_file(). As I explained in the previous chapter, PHP runs on most Linux servers as nobody or apache. Consequently, a folder must have minimum access permissions of 755 for scripts to open a file. If you also want your scripts to create or alter files, you normally need to set global access permissions of 777, the least secure setting. If PHP is configured to run in your own name, you can be more restrictive, because your scripts can create and write to files in any folder for which you have read, write, and execute permissions. On a Windows server, you need write permission to create or update a file. Configuration settings that affect file access Hosting companies can impose further restrictions on file access through php.ini. To find out what restrictions have been imposed, run on your website, and check the settings in PHP Core. Table 7-1 lists the settings you need to check and notes changes planned in PHP 6.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.