PHP Files Multiple Choice Questions

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? (Choose 2)

A) file_get_contents()
B) fgets()
C) fopen()
D) file()
E) readfile()

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

A) True
B) False

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
E) fstat() is an alias of stat()

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

5)
Which of the following functions reads the entire contents of a file?

A) fgets()
B) file_get_contents()
C) fread()
D) readfile()
E) file()

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.

7)
Assuming that image.jpg exists and is readable by PHP, how will the following script be displayed if called directly from a browser?

<?php
header ("Content-type: image/jpeg");
?>
<?php
readfile ("image.jpg");
?>

A) As a JPEG image
B) As a binary file for display within the browser
C) As a binary file for download
D) As a JPEG file for download
E) As a broken image

8)
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()
E) Read the file one character at a time

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

A) f_eof()
B) f_of()
C) feofs()
D) feof()

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

A) fgetc()
B) fgets()
C) fget()
D) fgetf()

Answers