our clients
Understanding paths in PHP
Ever wondered how to properly include files? Here's your chanceThere are two ways of including files in PHP: relative and absolute. Example code below shows how to properly include Thumbnailer class. PHP offers two including functions: include and require. The former should only be used for non important files like template files, the latter for libraries, classes etc.
<?php
// for example this is index.php file
// and Thumbnailer class is located in the same folder
// absolute inclusion
// dirname(__FILE__) will output the full path
// to the current file
// correct way
require dirname(__FILE__).'/Thumbnailer.php';
// if the Thumbnailer is located in the parent directory
// named 'classes'
require dirname(__FILE__).'/../classes/Thumbnailer.php';
// check this out
echo "File being executed: ". __FILE__ . "<br/>";
echo "Absolute directory of file being executed: ". dirname(__FILE__) . "<br/>";
// relative inclusion
// you should not use it
require 'Thumbnailer.php';
?>
Both examples will give a same result, but the latter can, on some other servers, cause problems if the INCLUDE_PATH constant is not set to . (dot). Usually it is set to .;.. which means PHP will always look for included files in the same directory and the parent directory.
Tutorials
-
How to install Wordpress 3
09/04/2011Installing Wordpress is easy and fun
-
Installing MySQL Windows
09/03/2011We will teach you how to install MySQL and get it working in PHP in this step by step tutorial.
-
Installing PHP 5.3 with Apache on Windows
09/03/2011We will teach you how to install PHP as an Apache module in this step by step tutorial.
-
How to install Apache on Windows
09/03/2011We will teach you how to setup Apache environment on Windows in this step by step tutorial.
-
Understanding paths in PHP
03/05/2011Ever wondered how to properly include files? Here's your chance
-
Batch processing tutorial
03/01/2011In this example we will process many photos from directory and save information about them into the database.
-
Create a thumb from uploaded image
04/02/2010Check out how to quickly create a thumb from uploaded image.