menu

PHP File Handling


1. What is the function used to write a string to a file in PHP?

file_put_contents()

file_get_contents()

fwrite()

fgets()


2. What is the function used to check if a file exists in PHP?

file_exists()

file_open()

file_close()

file_read()


3. What is the function used to read a single character from a file in PHP?

fgetc()

fgets()

fread()

fgetss()


4. What is the function used to close a file in PHP?

fclose()

fopen()

fwrite()

fread()


5. Which of the following is the correct way to open a file in PHP in binary mode?

fopen("file.bin", "rb");

fopen("file.bin", "r");

fopen("file.bin", "w");

fopen("file.bin", "a");


6. What is the function used to get the current position of the file pointer in PHP?

ftell()

fseek()

rewind()

fgetpos()


7. What is the function used to delete a file in PHP?

unlink()

delete()

remove()

erase()


8. Which of the following is the correct way to write data to a file in PHP?

fwrite($file, "data");

fread("data", $file);

fwrite("data", $file);

fread($file, "data");


9. What is the function used to read a specific number of bytes from a file in PHP?

fread()

fgetc()

fgets()

fgetss()


10. What is the mode used for opening a file in PHP for reading only?

r

w

a

x