menu

PHP File Handling


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

a

r

w

x


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

file_put_contents()

file_get_contents()

fwrite()

fgets()


3. 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()


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

ftell()

fseek()

rewind()

fgetpos()


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 function is used to write data to a file in PHP?

fwrite()

fread()

fopen()

fclose()


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

w

r

a

x


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

r

w

a

x


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


10. What is the function used to move the file pointer to a specified position in PHP?

fseek()

ftell()

rewind()

fsetpos()