PHP File Handling Aptitude Questions and Answers

PHP File Handling Aptitude: This section contains aptitude questions and answers on PHP File Handling. By Nidhi Last updated : December 15, 2023

This section contains Aptitude Questions and Answers on PHP File Handling.

1) There are the following statements that are given below, which of them are correct about file handling in PHP?
  1. PHP supports file handling to create, read, write, upload, and edit files
  2. We can perform operations with text files only in PHP
  3. Both of the above
  4. None of the above

2) Which of the following function is used to read an existing file in PHP?
  1. openfile()
  2. readfile()
  3. readf()
  4. read_f()

3) What will the output of below code, if specified file does not exist?
<?php
echo readfile("myfile.txt");
?>
  1. Error
  2. Warning
  3. Null
  4. 0

4) Which of the following functions are used for file handling in PHP?
  1. fopen()
  2. fread()
  3. fgets()
  4. fgetstr()

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

5) Which of the following function is used to print a message and exit from current php script?
  1. close()
  2. exit_script()
  3. die()
  4. die_script()

6) Which of the following file modes are used with fopen() function in PHP?
  1. "r"
  2. "w"
  3. "x"
  4. "a+"

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

7) Which of the following statement is correct about file mode "x" in fopen() in PHP?
<?php
$arr_state = array(
    "MP",
    "UP",
    "AP"
);
print "$arr_state[0], $arr_state[1], ";

if ($arr_state[3] == '') print "DELHI";
?>
  1. This file mode is used to create a new file for write-only, if the specified file already exists then fopen() function return FALSE in the 'x' file mode.
  2. This file mode is used to create a new file for write-only, if a specified file already exists then it erases complete data of the file and writes new data into the file.
  3. The 'x' file mode is not exist for fopen() function.
  4. None of the above

8) Which of the following function is used to get the length of the specified file?
  1. filelen()
  2. filelength()
  3. filesize()
  4. fsize()

9) What is the correct syntax of fread() function in PHP?
  1. fread($file_ptr, $num_of_bytes_to_read)
  2. fread($data_buffer)
  3. fread($file_ptr, $data_buffer)
  4. None of the above

10) Which of the following function is used to read a single line from the file in PHP?
  1. freadline()
  2. fgets()
  3. fgetline()
  4. fline()

11) Which of the following function is used to read a single character from the file in PHP?
  1. fgetchar()
  2. gethchar()
  3. fgetc()
  4. fgetch()

12) Which of the following function is used to delete a specified file?
  1. fdel()
  2. fdelete()
  3. unlink()
  4. deletefile()

13) Which of the following function is used to check a specified file is exist of not?
  1. is_file_exists()
  2. file_exists()
  3. file_exist()
  4. fileexist()

14) Which of the following function is used to copy the content of file into another file?
  1. fcopy()
  2. filecopy()
  3. file_copy()
  4. copy()

15) Which of the following function is used to check the end of the file?
  1. feof()
  2. eof()
  3. end_of_file()
  4. endoffile()

16) Which of the following function is used to read the complete file content?
  1. read_complete_file()
  2. read_complete_data()
  3. file_get_contents()
  4. None of the above

17) Which of the following directive is used to enable/disable file uploading in the "phh.ini" file?
  1. fileupload
  2. file_upload
  3. fileuploads
  4. file_uploads

18) Which of the following superglobal variable is used to upload a file in PHP?
  1. $_UPLOAD_FILE
  2. $_UPLOAD_FILES
  3. $_FILE
  4. $_FILES

19) Which of the following condition is used to check size limit 1KB to upload a file?
  1. if ($_FILES["fileToUpload"]["size"] > 1024)
  2. if ($_FILES["fileToUpload"]["size"] > 1KB)
  3. if ($_FILES["fileToUpload"]["limit"] > 1024)
  4. None of the above

20) Which of the following function is used to close a file in PHP?
  1. close()
  2. f_close()
  3. fclose()
  4. None of the above

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.