Source for file pcf_file.phpinc

Documentation is available at pcf_file.phpinc

  1. <?php
  2. /**
  3.   * Common Directory Functions
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    common
  7.   * @category   file
  8.   *
  9.   * @author     Peter Krebs (pk)<p.krebs@wpus.at>
  10.   * @copyright  (c) 2002-2005 by Peter Krebs and WURM und Partner Unternehmensservice GmbH.
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15.     pcf_require_class('OCSP_FILE',"common/");
  16.  
  17. /**
  18.   * returns a filename where some special char are converted
  19.   * unknown chars are replaced with _
  20.   *
  21.   * @param string $fileName 
  22.   * @param string $replChar 
  23.   *
  24.   * @return string 
  25.   *
  26.   * @version pk-05-03-17 $replChar added
  27.   ***/
  28. function pcf_checkFileName($fileName,$replChar="_"
  29. {
  30.     return OCSP_FILE::checkFileName($fileName,$replChar);
  31. }
  32.  
  33. /**
  34.  * returns a clean filepath (remove multiple $dirSep)
  35.  *
  36.  * @param string $filePath 
  37.  * @param char $dirSep 
  38.  * 
  39.  * @return string 
  40.  */
  41. function pcf_checkFilePath($filePath,$dirSep _OCSP_DIRSEP_)
  42. {
  43.     $filePath trim($filePath);
  44.     if (substr($filePath,0,1== $dirSep )
  45.     {
  46.         $str_ret $dirSep;
  47.     else {
  48.         $str_ret "";
  49.     }
  50.     
  51.     if ($arr_path explode($dirSep,$filePath))
  52.     {
  53.         $cha_sep "";
  54.         foreach($arr_path as $str_part)
  55.         {
  56.             if (!empty($str_part))
  57.             {
  58.                  $str_ret .= $cha_sep $str_part;
  59.                  $cha_sep=$dirSep;
  60.             }
  61.         }
  62.     }
  63.     return $str_ret;
  64. }
  65.  
  66. /**
  67.   * removes a file from the project
  68.   *
  69.   * this function is designed to bypass safe_mode restrictions for
  70.   * some allowed directories see $GLOBALS['BYPASS_SAFEMODE']['PROJ_DIRS']
  71.   *
  72.   * if $file is within this path a unlink shellscript is executed
  73.   * otherwise the php unlink command is executed
  74.   *
  75.   * @param string $file 
  76.   *
  77.   * @todo only in design state now just calls unlink($file)
  78.   *
  79.   ***/
  80. function pcf_fileunlink($file,$debug=FALSE{
  81.     unlink($file);
  82. }
  83.  
  84.  
  85. /**
  86.   * check if a file exists
  87.   *
  88.   * this function is designed to bypass safe_mode restrictions for
  89.   * some allowed directories see $GLOBALS['BYPASS_SAFEMODE']['PROJ_DIRS']
  90.   *
  91.   * @todo only in design state now just calls file_exists($file)
  92.   *
  93.   ***/
  94. function pcf_fileExists($file,$debug=FALSE{
  95.     if ($debugecho "<p><b>pcf_fileExists($file,$debug)</b></p>";
  96.     return file_exists($file);
  97. }
  98.  
  99.  
  100.  
  101. /**
  102.   * symlinks a file
  103.   *
  104.   * this function is designed to bypass safe_mode restrictions for
  105.   * some allowed directories see $GLOBALS['BYPASS_SAFEMODE']['PROJ_DIRS']
  106.   *
  107.   * @todo only in design state now just calls symlink($source,$dest)
  108.   *
  109.   ***/
  110. function pcf_fileLink($source,$dest,$debug=FALSE{
  111.     if ($debugecho "<p><b>pcf_fileLink($source,$dest,$debug)</b></p>";
  112.     return symlink($source,$dest);
  113. }
  114.  
  115. /**
  116.   * moves a file
  117.   *
  118.   * this function is designed to bypass safe_mode restrictions for
  119.   * some allowed directories see $GLOBALS['BYPASS_SAFEMODE']['PROJ_DIRS']
  120.   *
  121.   * @todo only in design state now just calls copy() and unlink()
  122.   *
  123.   ***/
  124. function pcf_fileMove($source,$dest,$debug=FALSE{
  125.     if ($debugecho "<p><b>pcf_fileMove($source,$dest,$debug)</b></p>";
  126.     if (copy($source,$dest)) {
  127.         unlink($source);
  128.         return TRUE;
  129.     else return FALSE;
  130. }
  131.  
  132. /**
  133.   * size of a file in bytes
  134.   *
  135.   * this function is designed to bypass safe_mode restrictions for
  136.   * some allowed directories see $GLOBALS['BYPASS_SAFEMODE']['PROJ_DIRS']
  137.   *
  138.   * @todo bypass safe_mode
  139.   *
  140.   * @param string $file 
  141.   * @param boolean $debug 
  142.   *
  143.   * @returns int
  144.   *
  145.   * @version pk-07-08-02
  146.   *
  147.   ***/
  148. function pcf_fileSize($file,$debug=FALSE{
  149.     if ($debugechoDebug(__FILE__,"<p><b>pcf_fileSize($file,$debug)</b></p>");
  150.     if (!empty($file&& file_exists($file)) return filesize($file);
  151.     return 0;
  152. }
  153.  
  154. /**
  155.   * returns the extension of a fileName (the last .xxx)
  156.   *
  157.   * @param string $fileName 
  158.   * @param boolean $debug 
  159.   *
  160.   * @return string 
  161.   *
  162.   * @since pk-05-09-09
  163.   *
  164.   * @var $a_parts 
  165.   ***/
  166. function pcf_fileGetExtension($fileName,$debug=FALSE{
  167.     if ($debugecho "<p><b>pcf_fileGetExtension($fileName)</b> (".__FILE__.")</p>";
  168.  
  169.     if (!strstr($fileName,".")) return "";
  170.     $a_parts=explode(".",$fileName);
  171.     return ".".$a_parts[sizeof($a_parts)-1];
  172. }
  173.  
  174. /**
  175.  * generates a unique file name
  176.  * @param string $fileName 
  177.  * @return string 
  178.  * @since pk-07-11-18
  179.  */
  180. function pcf_genUniqFileName($fileName)
  181. {
  182.     if (strstr($fileName,'.'))
  183.     {
  184.         $a_exts explode('.',$filename);
  185.         $s_ext=".".$a_exts[count($a_exts)-1];
  186.         return str_replace($s_ext,"_".uniqid(rand()true).$s_ext,$fileName);
  187.     else {
  188.         return $fileName."_".uniqid(rand()true);
  189.     }
  190. }
  191.  
  192.  
  193. /**
  194.  * checks if a file is a file (follow links)
  195.  * 
  196.  * @param string $file 
  197.  * 
  198.  * @return boolean 
  199.  * 
  200.  * @since pk-08-05-18
  201.  */
  202. function pcf_is_file($file)
  203. {
  204.     if (is_file($file))
  205.     {
  206.         return True;
  207.     else if (is_link($file&& ($file=readlink($file))) {
  208.         return pcf_is_file($file);
  209.     else {
  210.         return False;
  211.     }
  212.     
  213. }
  214. ?>

Documentation generated on Thu, 08 Jan 2009 17:47:47 +0100 by phpDocumentor 1.4.0a2