WorksheetsPHP File Handling
Total questions: 12
Worksheet time: 6mins
1. What does the readfile() function do in PHP?
Writes content to a file
Reads a file and writes it to the output buffer
Creates a new file
Delete a file
1. What is the purpose of the fopen() function in PHP?
To create a new directory
To delete a file
To close an open file
To open a file for reading or writing
2. What does the fwrite() function do in PHP?
Closes a file
Opens a file for reading
Writes data to a file
Reads data from a file
Which PHP function is used to open a file for reading or writing?
file_open()
open_file()
fopen()
file()
In fopen("mystory.txt", "r"), what does the mode "r" mean?
Read and write
Write only
Read only
Append to the file
What is the correct function to read a specific number of bytes from an open file?
readfile()
fread()
fopen()
fwrite()
What happens if you use fopen("newfile.txt", "w") on a non-existing file?
PHP will show an error
The file will be deleted
The file will be created
Nothing will happen
Why is it important to always close files after handling them in PHP?
To free up system resources
To delete the file
To move the file to another location
To encrypt the file
Ali opens a file with mode "r". He tries to write new data into it, but an error occurs. Why?
The file is locked for editing
The file is opened as read-only, not writable
The file does not exist
The file is already closed
Afif uses fopen("log.txt", "w") to open a file and writes a log message.
What will happen if log.txt already has old data inside?
New data will be added below old data
Old data will be kept, new data added at top
Old data will be deleted and replaced with new data
Nothing will happen because the file is in read mode
Kamut accidentally used "w" mode on a project file that contains important information. What is the immediate risk?
The file becomes read-only
The file might get locked
The existing file content will be permanently erased
The file will not open at all
Sarah wants to add her journal entry at the bottom of journal.txt without losing previous entries. Which mode should she use?
"r"
"w"
"a"
"r+"
