File System

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

Which of the following functions retrieve the entire contents of a file in such a way that it can be used as part of an expression? 1. file_get_contents() 2. fgets() 3. fopen() 4. file() 5. readfile()

A. Option 2 and 4
B. Option 1 and 5
C. Option 1 and 4
D. Option 3 and 4
Answer: _________
Question 2:

fgets() is used to read a file one line at a time.

A. True
B. False
Answer: _________
Question 3:

What is the difference between stat() and fstat()?

A. While stat() works on open file pointers, fstat() works on files specified by pathname
B. While fstat() works on open file pointers, stat() works on files specified by pathname
C. fstat() has nothing to do with files
D. stat() has nothing to do with files
Answer: _________
Question 4:

flock() is used to unlock a file so that two or more people do not get access to it at the same time.

A. True
B. False
Answer: _________
Question 5:

Which of the following functions reads the entire contents of a file? 1. fgets() 2. file_get_contents() 3. fread() 4. readfile() 5. file()

A. Option 3 and 5
B. Option 1, 3 and 4
C. Option 2, 4 and 5
D. Option 2 and 4
Answer: _________
Question 6:

What is the purpose of basename() function?

A. Returns the last accessed time of the file
B. Returns the first accessed time of the file
C. Strips of the path and returns the file name
D. Strips of the path and returns the folder name
Answer: _________
Question 7:

What should you do if your script is having problem recognizing file endings from a text file saved on a platform different from the one you’re reading it on?

A. Change the auto_detect_line_endings INI setting
B. Use a regular expression to detect the last letter of a line
C. Use fpos()
D. Use ftok()
Answer: _________
Question 8:

The ............ function checks if the "end-of-file" (EOF) has been reached.

A. f_eof()
B. f_of()
C. feofs()
D. feof()
Answer: _________
Question 9:

The ........... function is used to read a single character from a file.

A. fgetc()
B. fgets()
C. fget()
D. fgetf()
Answer: _________
Question 10:

The filesize() function returns the file size in ___________

A. bits
B. bytes
C. kilobytes
D. gigabytes
Answer: _________
Question 11:

Which one of the following PHP function is used to determine a file’s last access time?

A. fileltime()
B. filectime()
C. fileatime()
D. filetime()
Answer: _________
Question 12:

Which one of the following function is capable of reading a file into an array?

A. file()
B. arrfile()
C. arr_file()
D. file_arr()
Answer: _________
Question 13:

Which one of the following function is capable of reading a file into a string variable?

A. file_contents()
B. file_get_contents()
C. file_content()
D. file_get_content()
Answer: _________
Question 14:

Which one of the following function is capable of reading a specific number of characters form a file?

A. fgets()
B. fget()
C. fileget()
D. filegets()
Answer: _________
Question 15:

Which one of the following function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?

A. fgetsh()
B. fgetsp()
C. fgetsa()
D. fgetss()
Answer: _________
Question 16:

Which one of the following function outputs the contents of a string variable to the specified resource?

A. filewrite()
B. fwrite()
C. filewrites()
D. fwrites()
Answer: _________
Question 17:

Which function sets the file filename’s last-modified and last-accessed times?

A. sets()
B. set()
C. touch()
D. touched()
Answer: _________
Question 18:

Which function is useful when you want to output the executed command’s result?

A. out_cmm()
B. out_system()
C. cmm()
D. system()
Answer: _________
Question 19:

Which one of the following function reads a directory into an Array?

A. scandir()
B. readdir()
C. scandirectory()
D. readdirectory()
Answer: _________

Answer Key

1: C
2: A
3: B
4: B
5: C
6: C
7: A
8: D
9: A
Solution: Option A: fgetc() This function in PHP is used to read a single character from a file. It retrieves the next character from the file pointer and advances the file pointer position to the next character. Option B: fgets() The fgets() function is used to read a line from a file. It retrieves a line of text from the file pointer, including the newline character at the end of the line. Option C: fget() There is no fget() function in PHP related to file reading. This option is incorrect. Option D: fgetf() There is no fgetf() function in PHP related to file reading. This option is incorrect. Conclusion: The function used to read a single character from a file in PHP is fgetc() (Option A). This function is specifically designed to fetch individual characters from the file, making it the correct answer to the question.
10: B
11: C
Solution: The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.
12: A
13: B
14: A
Solution: Its prototype is string fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is assumed.
15: D
16: B
17: C
Solution: Its prototype is int touch(string filename [, int time [, int atime]]). It returns TRUE on success or FALSE on error.
18: D
19: A
Solution: It returns an array consisting of files and directories found in directory or returns FALSE on error.