File and Directory Handling - file open-close, copy, rename, delete, directory operations, file upload-download - Question Bank
1. When handling file uploads, what is the recommended practice for the temporary directory?
2. Which function is used to get the file size of a file in bytes?
3. Which function is used to get the last modified time of a file?
4. The `glob()` function is useful for finding pathnames matching a pattern. What does `glob('*.txt')` return?
5. Which PHP function returns an array of all files and directories within a given path, excluding '.' and '..', sorted alphabetically?
6. Which function is used to change the current working directory?
7. Which function is used to get the current working directory?
8. If you want to force the browser to display the file inline (if possible) rather than downloading it, which header should be used instead of 'attachment'?
9. What does the `Content-Type: application/octet-stream` header typically indicate?
10. Which PHP function can be used to read the contents of a file and send it directly to the output buffer for download?
11. To download a file from the server to the client's browser, what HTTP headers are typically required?
12. What is the primary security benefit of using `move_uploaded_file()` instead of `copy()` or `rename()` for uploaded files?
13. Which PHP function is used to move a temporarily stored uploaded file to a permanent location?
14. Which constant represents the error code for a file that is too large to be uploaded, as defined by `upload_max_filesize` in php.ini?
15. The `$_FILES['userfile']['error']` key contains an error code. What does a value of `UPLOAD_ERR_OK` (which is 0) signify?
16. Which key in the `$_FILES` array indicates the size of the uploaded file in bytes?
17. The `$_FILES['userfile']['type']` key provides the MIME type of the uploaded file. However, this value is:
18. Which key within the `$_FILES` array holds the original filename of the uploaded file on the client's machine?
19. Which superglobal array in PHP contains information about uploaded files?
20. When a file is uploaded via an HTML form using `enctype='multipart/form-data'`, where is the uploaded file initially stored by PHP?
21. What is the typical directory structure used by PHP for handling file uploads?
22. Which function is used to get information about a file, such as size, permissions, and modification time?
23. The scandir() function returns an array containing:
24. To list the files and directories inside a specified directory, which PHP function can be used?
25. Which PHP function is used to check if a given path is a directory?
26. Which PHP function is used to check if a given path is a regular file?
27. What does the FILE_APPEND flag do when used with file_put_contents()?
28. Which PHP function is used to write a string to a file?
29. What is the primary difference between file() and file_get_contents()?
30. Which PHP function is used to read the contents of a file into an array, with each array element representing a line of the file?
31. The rmdir() function can only remove empty directories. What happens if you try to remove a non-empty directory?
32. Which PHP function is used to remove a directory?
33. The second parameter of mkdir() allows specifying permissions. What does the 'recursive' flag (e.g., `mkdir('path/to/new/dir', 0777, true);`) do?
34. What is the default permission mode for a directory created with mkdir()?
35. Which PHP function is used to create a directory?
36. To check if a file exists before attempting to delete it, which function is commonly used?
37. What does unlink() return on success?
38. Which PHP function is used to delete a file?
39. If the source and destination paths in rename() are on different filesystems, the behavior depends on the operating system. On POSIX systems, this operation is usually an alias for:
40. Which PHP function is used to rename or move a file?
41. The copy() function returns TRUE on success and FALSE on failure. What happens if the destination file already exists?
42. Which PHP function is used to copy a file from one location to another?
43. What is the return value of fclose() upon successful closure of a file?
44. Which PHP function is used to close an open file pointer?
45. What does the 'b' modifier in file opening modes (e.g., 'rb', 'wb') signify?
46. To append data to a file, which mode should be used with fopen()?
47. Which mode in fopen() is used to open a file for writing only; place the file pointer at the beginning of the file and truncate the file length to 0?
48. What is the primary purpose of the 'r' mode when opening a file with fopen()?
49. Which PHP function is used to open a file and return a file pointer?