Workshop


The workshop is designed to help you anticipate possible questions, review what you've learned, and begin putting your knowledge into practice.

Quiz

1.

What functions do you use to add library code to the currently running script?

2.

What function do you use to find out whether a file is present on your filesystem?

3.

How do you determine the size of a file?

4.

What function do you use to open a file for reading or writing?

5.

What function do you use to read a line of data from a file?

6.

How can you tell when you've reached the end of a file?

7.

What function do you use to write a line of data to a file?

8.

How do you open a directory for reading?

9.

What function do you use to read the name of a directory item after you've opened a directory for reading?

10.

Which function is used to open a pipe to a process?

11.

How can you read data from a process after you have opened a connection? What about writing data?

12.

How can you escape user input to make it a little safer before passing it to a shell command?

Answers

1.

You can use the require() or include() statement to incorporate PHP files into the current document. You could also use include_once() or require_once().

2.

You can test for the existence of a file with the file_exists() function.

3.

The filesize() function returns a file's size in bytes.

4.

The fopen() function opens a file. It accepts the path to a file and a character representing the mode. It returns a file resource.

5.

The fgets() function reads data up to the buffer size you pass it, the end of the line, or the end of the document, whichever comes first.

6.

The feof() function returns true. when the file resource it's passed reaches the end of the file.

7.

You can write data to a file with the fputs() function.

8.

The opendir() function enables you to open a directory for reading.

9.

The readdir() function returns the name of a directory item from an opened directory.

10.

The popen() function is used to open a pipe to a process.

11.

You can read and write to and from a process just as you can with an open file, namely with feof() and fgets() for reading and fputs() for writing.

12.

If user input is part of your shell command, you can use the escapeshellcmd() or escapeshellarg() function to properly escape it.

Activities

  1. Create a form that accepts a user's first and second name. Create a script that saves this data to a file.

  2. Create a script that reads the data file you created in the first activity. In addition to writing its contents to the browser (adding a <br/> tag to each line), print a summary that includes the number of lines in the file and the file's size.




Sams Teach Yourself PHP, MySQL And Apache All in One
Sams Teach Yourself PHP, MySQL and Apache All in One (3rd Edition)
ISBN: 0672328739
EAN: 2147483647
Year: 2004
Pages: 327

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net