Title:Opening a File with PHPContributor: Randall Goguen (aka Ranman)
Last Update: Wednesday July 19 00:13 EDT 2000
Example 1:# Opening a file for reading.
<?
$file = file("file.txt");
$j = count($file);
for($i=0; $i<$j; $i++) {
echo "$file[$i]<br>";
}
?>
Example 2:# Opening a file for reading.
<?
$my_file = "file.txt";
$fp = fopen($my_file, 'r');
$buffer = fread($fp, filesize($my_file));
echo $buffer;
fclose($fp);
?>
Example 3:# Opening a file for writing.
<?
$my_file = "/path/to/file.txt";
$message = "This is a line of text"."\n";
$fp = fopen ($my_file, 'w');
fwrite ($fp, $message);
fclose ($fp); }
?>
Example 4:# Opening a file for appending.
<?
$my_file = "/path/to/file.txt";
$message = "This is a line of text"."\n";
$fp = fopen ($my_file, 'a');
fwrite ($fp, $message);
fclose ($fp);
?>
# PHP Filesystem functions.
int copy(string source_file, string destination_file)
Copy a file
int fclose(int fp)
Close an open file pointer
int feof(int fp)
Test for end-of-file on a file pointer
int fflush(int fp)
Flushes output
string fgetc(int fp)
Get a character from file pointer
array fgetcsv(int fp, int length)
Get line from file pointer and parse for CSV fields
string fgets(int fp, int length)
Get a line from file pointer
string fgetss(int fp, int length [, string allowable_tags])
Get a line from file pointer and strip HTML tags
array file(string filename [, int use_include_path])
Read entire file into an array
bool flock(int fp, int operation [, int wouldblock])
Portable file locking
int fopen(string filename, string mode [, int use_include_path])
Open a file or a URL and return a file pointer
int fpassthru(int fp)
Output all remaining data from a file pointer
int fread(int fp, int length)
Binary-safe file read
mixed fscanf(string str, string format [, string ...])
Implements a mostly ANSI compatible fscanf()
int fseek(int fp, int offset [, int whence])
Seek on a file pointer
int fstat(int fp)
Stat() on a filehandle
int ftell(int fp)
Get file pointer's read/write position
int ftruncate(int fp, int size)
Truncate file to 'size' length
int fwrite(int fp, string str [, int length])
Binary-safe file write
array get_meta_tags(string filename [, int use_include_path])
Extracts all meta tag content attributes from a file and returns an array
int mkdir(string pathname, int mode)
Create a directory
int pclose(int fp)
Close a file pointer opened by popen()
int popen(string command, string mode)
Execute a command and open either a read or a write pipe to it
int readfile(string filename [, int use_include_path])
Output a file or a URL
string realpath(string path)
Return the resolved path
int rename(string old_name, string new_name)
Rename a file
int rewind(int fp)
Rewind the position of a file pointer
int rmdir(string dirname)
Remove a directory
int set_file_buffer(int fp, int buffer)
Set file write buffer
int set_socket_blocking(int socket_descriptor, int mode)
Set blocking/non-blocking mode on a socket
array socket_get_status(resource socket_descriptor)
Return an array describing socket status
bool socket_set_timeout(int socket_descriptor, int seconds, int microseconds)
Set timeout on socket read to seconds + microseonds
string tempnam(string dir, string prefix)
Create a unique filename in a directory
int tmpfile(void)
Create a temporary file that will be deleted automatically after use
int umask([int mask])
Return or change the umask
int unlink(string filename)
Delete a file
Anyone who wishes to make additions or changes to this
PHP Tip email them to webmaster@linuxguruz.org
This document is Copyright (c) 1999, 2000 by LinuxGuruz