Day 26 – Directory Operations

Zend PHP Certification

Now that we’ve talked about files, it’s time to talk about directory access.  PHP has a whole variety of functions designed just for this!  Here are the important ones:

  • chdir($dir): Change working directory
  • $dir = getcwd(): Get working directory
  • mkdir($dir, [$permission], [$recursive]): Create a new directory with permission model (in octal) $permission
  • is_dir($directory): Check if path is an actual directory
  • chmod($file, $permission): Change permission of a file/directory with a permission model (also in octal)
  • chgrp($file, $group): Change group ownership of a file/directory
  • chown($file, $name): Change ownership of a file/directory
  • $array = scandir($folder): Return a list of files/directories in the specified folder

Network Access

Basic network access is performed very similarly to file access.

$file = fopen(“http://www.google.com”);
  1. $content = "";
  2.  
  3. while ($temp = fread($file, 1000))
  4.   $content .= $temp;
  5.  
  6. fclose($file);

Obviously, you cannot use ALL the same functions as for example, you cannot write to a website stream.

This is the most basic form of access, you can also use curl (which I love) for a more advanced approach.

Tomorrow I’ll cover Advanced Streaming.

No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>