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 read the entire contents of a file into a string in PHP?

file_get_contents()

file_put_contents()

fread()

fgets()


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

fgets()

fwrite()

fopen()

fclose()


4. What is the mode used for opening a file in PHP for writing only?

w

r

a

x


5. Which of the following is the correct way to rename a file in PHP?

rename("oldname.txt", "newname.txt");

move("oldname.txt", "newname.txt");

change("oldname.txt", "newname.txt");

switch("oldname.txt", "newname.txt");


6. 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");


7. What is the function used to get the size of a file in PHP?

filesize()

file_get_size()

file_size()

get_file_size()


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

r

w

a

x


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

fgetc()

fgets()

fread()

fgetss()


10. What is the mode used for opening a file in PHP for appending data?

a

r

w

x