Profile Picture
IT Made Easy
The site provides some rough IT Notes that make your life easier. The site currently has notes on HTML, CSS, Regex, OOPS, JS, JQuery, PHP, Java, ASP.NET, C#, Database, Linux, URL Rewrite, SEO, Project Management and Hosting. Please do share this site if you like.

Streams and Network Programing



File opening modes

  • r,w,a where r represents read, w represents wrrite, a represents append.
  • + will make it both read and write.
  • a makes file pointer point to the end which is otherwise at beginning.s
  • w additionally truncates filesize to 0
  • x creates a new file

if (!file_exist ("filename.txt"))


throw new Exception ("The file does not exists");


$file = fopen("filename.txt", "r");

while (!feof($file))


$txt .= fread($file, 1);            //Last parameter number of bytes. fgets() stops at newline character

fwrite($file, $txt);



//This will move file pointer by itself. The second parametter is the number of bytes to be moved (neagtive or positive) and third is the loaction from where to move - SEEK_SET (start), SEEK_CUR (current) and SEEK_END (end)


  • fgetcsv() and fputcsv() vastly simplify the task of accessing CSV files.
  • file_get_contents() and file_put_contents() simply file writing


  • chdir("path") - changes directory path
  • getcwd() - gets current working directory
  • mkdir ("path", 0666, true); The second parameter gives access mode and last if set to true any missing directories in path will be created. Normally last directory is created.
  • is_dir()—Checks if the path is a directory
  • • is_executable()—Checks if the path is executable
  • • is_file()—Checks if the path exists and is a regular file
  • • is_link()—Checks if the path exists and is a symlink
  • • is_readable()—Checks if the path exists and is readable
  • • is_writable()—Checks if the path exists and is writable
  • • is_uploaded_file()—Checks if the path is an uploaded file (sent via HTTP POST)
  • File permissions on UNIX systems can be changedby using chmod(), chgrp() and chown() where path and access mode provided


  • Simple Network Access can be done by uing some of the file functions
  • You can create socket servers and clients using the stream functions stream_socket_server() and stream_socket_client()
  • Stream filters allow you to pass data in and out of a stream through a series of filters that can alter it dynamically like say filter for compression

IT Notes

by VinodSebastian

IT Downloads