1. Home
  2. Computing & Technology
  3. PHP / MySQL

fopen () PHP Function

By , About.com Guide

Definition: Opens a file in PHP to read, write, or rewrite to. It is phrased as fopen ( filename, mode)

Modes:
r - Reading only, beginning of file
r+ - Reading and writing, beginning of file
w - Writing only, beginning of file
w+ - Writing and reading, beginning of file
a - Writing only, end of file
a+ - Writing and reading, end of file
x - Create and open for writing only, beginning of file
x+ - Create and open for reading and writing, beginning of file

If the file does not exist and you use w, w+, a or a+ it will attempt to create the file.

Examples: Some examples of opening different files:

<?php
$a = fopen("/home/files/yourfile.txt", "r");
$b = fopen("yourfile.gif", "w");
$c = fopen("http://www.yoursite.com/", "r");
$d = fopen("ftp://user:password@yoursite.com/yourfile.txt", "w");
?>
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Fopen - PHP Open File - PHP Fopen

©2009 About.com, a part of The New York Times Company.

All rights reserved.