PHP_Chapter05_ReviewQuestions

True/False
Indicate whether the statement is true or false.

____	1.	PHP recognizes two types of files: binary and text.

____	2.	You append the \n carriage return escape sequence to the end of a line to identify the end of a line on a UNIX/Linux platform.

____	3.	PHP provides the chper() function for changing the permission of a file from within PHP.

____	4.	The three levels of permissions for files and directories are Read, Write, and Delete.

____	5.	The three levels of access for files and directories are User, Group, and Other.

____	6.	The fileperms() function allows the user to read the permissions associated with a particular file.

____	7.	The chdir() function changes to the name of the specified directory.

____	8.	A handle is a special type of variable that PHP uses to represent a resource, such as a file or directory.

____	9.	You can use the opendir() function to return the file and directory names from the open directory.

____	10.	The directory pointer is a way of keeping track of where you are in a directory.

____	11.	The scandir() function returns an indexed array containing the names of files and directories in a specified directory.

____	12.	The scandir() function sorts the returned entries in the order in which they are stored by the operating system.

____	13.	You use the createDir() function to create a new directory.

____	14.	The file_exists() function determines whether a file or directory exists.

____	15.	An additional form attribute, enctype, with a value of "multipart/form-data" must be used to upload files.

____	16.	You can specify the maximum size of an uploaded file using MAX_FILE SIZE as a hidden input field below the file input field.

____	17.	The move_uploaded_file() function moves the uploaded file from its temporary location to the permanent destination.

____	18.	The file_write_contents() function writes a text string as a file.

____	19.	Both the echo() and print() statements send data to an input stream.

____	20.	You use the fopen() function to open a handle to a file stream.

____	21.	The a+ mode argument opens the specified file for reading only and places the file pointer at the beginning of the file.

____	22.	If you want to open a file for reading and writing and place the file pointer at the end of the file, you use a mode argument of “a+”.

____	23.	When you are finished with a file stream, you use the statement fopen($handle); to ensure that the file doesn’t keep consuming space in your computer’s memory.

____	24.	You can use the fwrite() function to incrementally write data to a text file.

____	25.	You would use the file_put_contents() function to quickly replace the contents of a file or append data to the end of an existing file.

____	26.	To prevent multiple users from modifying a file simultaneously, you need to use the file_lock() function.

____	27.	The syntax for the copy_file() function is copy_file(source, destination).

____	28.	You can use the delete() function to delete files.

____	29.	Some operating systems always list two directory entries named “.” and “..”, which refer to the current directory and the directory that contains the current directory.

____	30.	One way to move a file in PHP is to copy with file with the copy() function, and then delete the original file with the unlink() function.

Multiple Choice
Identify the choice that best completes the statement or answers the question.

____	31.	On a Macintosh platform, you append the ____ carriage return escape sequence to the end of the line.
a.	\n	c.	\rn	
b.	\r	d.	\nr	

____	32.	The second digit in the file permission code assigns permissions to the ____.
a.	group	c.	user	
b.	other	d.	group/user	

____	33.	The ____ function returns an indexed array containing the names of files and directories in the specified directory.
a.	readdir()	c.	scandir()	
b.	opendir()	d.	closedir()	

____	34.	When a form is posted, information from the uploaded file is stored in the ____ autoglobal array.
a.	$_FILES[]	c.	FILE_UPLOAD[]	
b.	$_UPLOAD[]	d.	UPLOAD_FILES[]	

____	35.	The ____ function writes a text string and creates the file if it does not exist.

a.	file_write_contents()	c.	file_put_contents()	
b.	file_create_contents()	d.	file_make_contents()	

____	36.	The ____ constant instructs PHP to append data to any existing contents in a specified filename instead of overwriting it.

a.	FILE_APPEND	c.	FILE_INCLUDE	
b.	FILE_ADD	d.	APPEND_TO_FILE	

____	37.	When a text file contains a single block of text, the ____ function would read the entire contents of the file into a string.

a.	file_read_contents()	c.	file_extract_contents()	
b.	file_open_contents()	d.	file_get_contents()	

____	38.	The ____ function reads the contents of a text file that stores each individual line as an element of an indexed array.
a.	file()	c.	read_file()	
b.	get_file()	d.	open_file()	

____	39.	Using a value of ____ for the mode argument of the fopen() function opens the specified file for reading and writing and places the file pointer at the end of the file.
a.	w	c.	r+	
b.	r	d.	a+	

____	40.	When you are finished working with a file stream, you use the ____ function to ensure that the file does not keep taking up space in your computer’s memory.
a.	file_close()	c.	close_stream()	
b.	exit_file()	d.	fclose()	

____	41.	Because the fopen() function must be used with the ____ function, you can specify what type of operations can be performed on the file and where and how the data will be written.
a.	file_put_contents()	c.	readfile()	
b.	file_get_contents()	d.	fwrite()	

____	42.	The ____ argument of the fwrite() function allows you to specify the maximum number of bytes that should be written.

a.	size	c.	range	
b.	length	d.	max_length	

____	43.	The operational constant of the flock() function that opens the file with an exclusive lock for writing is the ____.
a.	LOCK_EX	c.	LOCK_NB	
b.	LOCK_SH	d.	LOCK_UN	

____	44.	Instead of reading a large text file into PHP, you can use the ____ to iterate through a text file.
a.	file handler	c.	data array	
b.	file pointer	d.	mode operator	

____	45.	Every time you use the ____ function, the file pointer moves to the next character in the file.
a.	fgetc()	c.	fclose()	
b.	fopen()	d.	fileread()	

____	46.	What function returns a line and moves the file pointer to the next line?

a.	fgetc($handle)	
b.	fgetcsv(handle, length[, delimiter, string_enclosure])	
c.	fgets($handle[, length])	
d.	fgetss(handle, length[, allowed_tags])	

____	47.	What function returns a line that ends with a specified delimiter and moves the file pointer to the next line?

a.	fgetcsv(handle, length[, delimiter, string_enclosure])	
b.	stream_get_line($handle, length, delimiter)	
c.	fgets(handle[, length])	
d.	fgetss(handle, length[, allowed_tags])	

____	48.	What function returns a line, strips any XHTML tags the line contains, and then moves the file pointer to the next line?
a.	fgetcsv(handle, length[, delimiter, string_enclosure])	
b.	stream_get_line)$handle, length, delimiter)	
c.	fgetss($handle, length[, allowed_tags])	
d.	fgets(handle[, length])	

____	49.	With the exception of the ____ function, each time you call a function that iterates through a text file, the file pointer automatically moves to the next line in the text file.
a.	fopen()	c.	fgetc()	
b.	fclose()	d.	feof()	

____	50.	What function returns a value of true when the file pointer reaches the end of the file?
a.	end_of_file()	c.	eof()	
b.	feof()	d.	file_end()	

____	51.	Two arguments, source and destination, are used with the ____ function.
a.	copy()	c.	file_copy()	
b.	copy_file()	d.	dup_file()	

____	52.	The two arguments required for the rename() function are ____. 
a.	previous_name,new_name	c.	current_name,new_name	
b.	old_name,new_name	d.	previous_name,current_name	

____	53.	What function is used to delete files?
a.	delete()	c.	unlink()	
b.	delete_file()	d.	del_file()	

____	54.	The ____ function should be used before deleting files and directories to determine if the file or directory name exists.

a.	file_exists()	c.	file_dir_exists()	
b.	dir_exists()	d.	dir_file_exists()	

____	55.	What function is used to copy the names of the files in a directory to an array?
a.	readdir()	c.	scandir()	
b.	copydir()	d.	list_dir()	

____	56.	The ____ function only works when there are “.” and “..” are the only two entries present in a directory.
a.	del_directory()	c.	delete_directory()	
b.	rmdir()	d.	remove_directory()	

PHP_Chapter05_ReviewQuestions
Answer Section

TRUE/FALSE

	1.	REF:	234

	2.	REF:	234

	3.	REF:	236

	4.	REF:	236

	5.	REF:	236

	6.	REF:	237

	7.	REF:	238

	8.	REF:	238 - 239

	9.	REF:	239

	10.	REF:	239

	11.	REF:	240

	12.	REF:	240

	13.	REF:	241

	14.	REF:	243

	15.	REF:	247

	16.	REF:	247

	17.	REF:	249

	18.	REF:	257

	19.	REF:	267

	20.	REF:	268

	21.	REF:	268

	22.	REF:	268

	23.	REF:	270

	24.	REF:	270

	25.	REF:	270

	26.	REF:	272

	27.	REF:	278

	28.	REF:	281

	29.	REF:	282

	30.	REF:	282

MULTIPLE CHOICE

	31.	REF:	234

	32.	REF:	236

	33.	REF:	240

	34.	REF:	248

	35.	REF:	257

	36.	REF:	261

	37.	REF:	262

	38.	REF:	264

	39.	REF:	268

	40.	REF:	270

	41.	REF:	270

	42.	REF:	271

	43.	REF:	272

	44.	REF:	275

	45.	REF:	275

	46.	REF:	275

	47.	REF:	275

	48.	REF:	275

	49.	REF:	275

	50.	REF:	275

	51.	REF:	278

	52.	REF:	280

	53.	REF:	281

	54.	REF:	281

	55.	REF:	282

	56.	REF:	282