menu

PHP File Handling


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

fread()

fgetc()

fgets()

fgetss()


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

w

r

a

x


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

fclose()

fopen()

fwrite()

fread()


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

fseek()

ftell()

rewind()

fsetpos()


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

fwrite($file, "data");

fread("data", $file);

fwrite("data", $file);

fread($file, "data");


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


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

file_exists()

file_open()

file_close()

file_read()


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

a

r

w

x


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

fgets()

fwrite()

fopen()

fclose()