LinuxGuruz
Toll Free Numbers
Custom Search
MAIN MENU
Main Page
IT Jobs
IPTABLES
Linux Forum
HTML Forum
PHP Forum
MySQL Forum
Linux FAQ
Linux Articles
About Us
Privacy Policy

ADD TO FAVORITES


MARC

Mailing list ARChives
- Search by -
 Subjects
 Authors
 Bodies





FOLDOC

Computing Dictionary






Cheap UK Web Hosting Provider

Cheap Dedicated Servers UK

Cheap Linux VPS Hosting UK

Cheap Cloud Hosting UK



Icons
Icons


free brochure template
Free Brochure Template

Web Hosting

Domain Names

Web Design

Reseller Hosting

Registro de Dominios

Reseller Hosting


Toll Free Number for $2.00/Month!!!

Toll Free Number for $2.00/Month!!!
Opening a File with PHP

Title:       Opening a File with PHP
Contributor: 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

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page


www.PHP.net Search Engine


Restrict the search to:
Copyright © 1999, 2000 The PHP Development Team.
Submit a PHP Tutorial

Title:

Contributor:

IRC NICK: (optional)

E-Mail Address: (optional)

Tutorial:

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page

RESOURCE LINKS
Linux
Apache
HTML
PHP
MySQL
PostgreSQL
Oracle
CGI
Perl
Java
C/C++
Bash
Tcl
Networking
Security
ISP
IRC
Xwindow
Laptop
Graphics
Hardware
Reference
Misc

Broadband


filing cabinet

  • Buy Batteries for Laptops and Cameras
  • Notebooks
  • Michael Fertik
  • Reputation Defender

  • XP Style Icons
    XP Style Icons


    Network Certification


    Network Security


    Wireless Networking


    Canadian
    Web Hosting in Canada


    Drummer Portal


    Mending Media

    The Path Of
    Most Resistance


    Toll Free Number for $2.00/Month!!!

    Toll Free Number for $2.00/Month!!!


    Linux

    The Distributions





    Linux

    The Software





    Linux

    The News




    webmaster@linuxguruz.com
    Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 and 2009 by LinuxGuruz