PHP

PHP: Print File Script

<?php
    // connect to handle a file
    $file_handler = fopen("http://www.mysite.com/sitenotes.txt", "r");
    /* to open a local file use this instead
    $file_handler = fopen("data.txt", "r");
    */
    // read the contents
    $contents = fread($file_handler, filesize($file));
    // close the file
    fclose($file_handler);
    // print the contents on your page
    echo $contents;
?>
Tags

PHP: Including PHP Resource Files

include v.s. require

  • include and require only differ in that
    • require -  script will HALT if the file specified is not found
    • include -  script will CONTINUE if the file specified is not found

 

include

include 'include/init.inc.php';
  • include will include the file - even if already included - as an overwrite.
  • Previous variable declarations and functions will be replaced.

 

include_once

include_once 'include/init.inc.php';
  • include_once will ONLY include the file if NOT already included.
  • if file already included, this statement is basically ignored

 

require

require 'include/init.inc.php';
  • Require will include the file - even if already included - as an overwrite.
  • Previous variable declarations and functions will be replaced.

 

Tags
Subscribe to PHP