file handling Flashcards

1
Q

fopen(“testfile.txt”, ‘w’)

A

Opens a file called testfile, the second parameter ‘w’ tells the function to open the file for writing. The function creates the file if it doesn’t already exist. Be careful when playing around with these functions: if the file already exists, the w mode parameter causes the open call to delete the old contents (even if you don’t write anything new)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

fread

A

Reads from file
fread($fh, 3); // Requests the first 3 characters of file assigned to $fh

The read function is commonly used with binary data. But if you use it on text data that spans more than one line, remember to count newline characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

fwrite

A

Writes to file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

fclose

A

Closes file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

copy(‘testfile.txt’, ‘testfile2.txt’)

A

Copies testfile.txt to testfile2.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

moving a file

A

To move a file, rename it with the rename function:

rename(‘testfile2.txt’, ‘testfile2.new’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

deleting a file

A

To delete a file, use the unlink function:

unlink(‘testfile2.new’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

file_exists

A

Returns TRUE if the file exists or FALSE if it doesn’t:

file_exists(‘testfile2.new’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

fseek

A

Moves the file pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly