tailieunhanh - PHP and MySQL Web Development - P77

PHP and MySQL Web Development - P77: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 352 Chapter 16 Interacting with the File System and the Server Using Program Execution Functions We ll move away from the file system functions now and look at the functions that are available for running commands on the server. This is useful when you want to provide a Web-based front end to an existing command line-based system. For example we have used these commands to set up a front end for the mailing list manager will use these again when we come to the case studies later in this book. There are four main techniques you can use to execute a command on the Web server. They are all pretty similar but there are some minor differences. 1. exec The exec function has the following prototype string exec string command array result int return_value You pass in the command that you would like executed for example exec ls -la The exec function has no direct output. It returns the last line of the result of the command. If you pass in a variable as result you will get back an array of strings representing each line of the output. If you pass in a variable as return_value you will get the return code. 2. passthru The passthru function has the following prototype void passthru string command int return_value The passthru function directly echoes its output through to the browser. This is useful if the output is binary for example some kind of image data. It returns nothing. The parameters work the same way as exec s parameters do. 3. system The system function has the following prototype string system string command int return_value The function echoes the output of the command to the browser. It tries to flush the output after each line assuming you are running PHP as a server module which distinguishes it from passthru . It returns the last line of the output upon success or false upon failure . The parameters work the same way as in the other functions. Using Program Execution Functions 353 4. Backticks We mentioned these briefly in Chapter 1 PHP Crash .

TỪ KHÓA LIÊN QUAN