PHP File Handling MCQs
PHP File Handling MCQs : This section focuses on "File Handling" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. The PHP ________ function is used to open a file.
A. open()
B. fopen()
C. create()
D. insert()
View Answer
Ans : B
Explanation: The PHP fopen() function is used to open a file.
2. fopen() requires _______ arguments.
A. 0
B. 1
C. 2
D. 3
View Answer
Ans : C
Explanation: It requires two arguments stating first the file name and then mode in which to operate.
3. The purpose of r+ mode is?
A. Opens the file for reading and writing
B. Places the file pointer at the beginning of the file
C. Places the file pointer at the end of the file
D. Both A and B
View Answer
Ans : D
Explanation: r+ : Opens the file for reading and writing.Places the file pointer at the beginning of the file.
4. If an attempt to open a file fails then fopen returns a value of ?
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : B
Explanation: If an attempt to open a file fails then fopen returns a value of false otherwise it returns a file pointer which is used for further reading or writing to that file.
5. The files length can be found using the _______function.
A. fsize()
B. fcount()
C. filesize()
D. count()
View Answer
Ans : C
Explanation: The files length can be found using the filesize() function which takes the file name as its argument and returns the size of the file expressed in bytes.
6. Which of the following is true about
a+ mode?
A. Opens the file for reading and writing only.
B. Places the file pointer at the end of the file.
C. If files does not exist then it attempts to create a file.
D. All of the above
View Answer
Ans : D
Explanation: All of the above are true about a+.
7. The filesize() function returns the file size in ___________
A. bits
B. bytes
C. kilobytes
D. gigabytes
View Answer
Ans : B
Explanation: The function filesize() returns the size of the specified file and it returns the file size in bytes on success or FALSE on failure.
8. 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()
View Answer
Ans : C
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.
9. What is the default value of max_input_time directive?
A. 30 seconds
B. 120 seconds
C. 1 second
D. 60 seconds
View Answer
Ans : D
Explanation: The default value of the max_input_time directive is 60 seconds.
10. Close the file with fclose() function.
A. Yes
B. No
C. Can be yes or no
D. Can not say
View Answer
Ans : A
Explanation: Yes, Close the file with fclose() function.
Discussion