CorujaFileManipulation.class.php
Go to the documentation of this file.00001 <?php
00012 class CorujaFileManipulation
00013 {
00044 public static function getRelativePath( $strFileFrom, $strFileTo, $booValidPath = true )
00045 {
00046
00047
00048 $strFileFrom = str_replace( "\\" , "/" , $strFileFrom );
00049 $strFileTo = str_replace( "\\" , "/" , $strFileTo );
00050
00051 if( $booValidPath
00052 && ( ! is_dir( $strFileFrom ) || ! is_dir( $strFileTo ) )
00053 )
00054 {
00055 throw new InvalidArgumentException("Invalid parameter: strFileFrom: ".$strFileFrom." strFileTo: ".$strFileTo);
00056 }
00057
00058
00059 if( $strFileFrom == $strFileTo )
00060 {
00061 $strReturnPath = './';
00062 }
00063 else
00064 {
00065
00066 $arrFileFrom = explode( '/', $strFileFrom );
00067 $arrFileTo = explode( '/', $strFileTo );
00068
00069
00070 while(
00071 current( $arrFileFrom ) == current( $arrFileTo )
00072 && count( $arrFileFrom ) > 0
00073 )
00074 {
00075 array_shift( $arrFileFrom );
00076 array_shift( $arrFileTo );
00077 }
00078
00079 $arrReturnPath = array();
00080
00081
00082 foreach( $arrFileFrom as $strFolder )
00083 {
00084 if( $strFolder != "" ) {
00085 $arrReturnPath[] = "..";
00086 }
00087 }
00088
00089 foreach( $arrFileTo as $strFolder )
00090 {
00091 $arrReturnPath[] = $strFolder;
00092 }
00093
00094 $strReturnPath = implode( '/', $arrReturnPath );
00095 }
00096 return $strReturnPath;
00097 }
00098
00113 public static function isRelativePath( $strFile )
00114 {
00115 $strFile = str_replace( "\\", "/", $strFile);
00116 if(
00117 ( strpos( $strFile, "./") === 0 )
00118 or
00119 ( strpos( $strFile, "../") === 0 )
00120 )
00121 {
00122 return true;
00123 }
00124 elseif( strpos( $strFile, "/") === false )
00125 {
00126 return true;
00127 }
00128 else
00129 {
00130 return false;
00131 }
00132 }
00133
00140 public static function getPathOfFile( $strFile )
00141 {
00142 return str_replace( "\\" , "/" , str_replace( basename( $strFile ) , "" , $strFile ) );
00143 }
00144 }
00145 ?>