menu

PHP File Handling


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


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

fclose()

fopen()

fwrite()

fread()


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


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


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

file_put_contents()

file_get_contents()

fwrite()

fgets()


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

fseek()

ftell()

rewind()

fsetpos()


7. Which of the following is the correct way to check the end of a file in PHP?

feof($file)

eof($file)

end_of_file($file)

is_eof($file)


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

fgetc()

fgets()

fread()

fgetss()


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

fgets()

fwrite()

fopen()

fclose()


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

file_exists()

file_open()

file_close()

file_read()