<?php
include_once("fileupload.class.php");
include_once("locale.class.php");
include_once("compress.class.php");
/**
* FileUpload - To handle the file/dir functions
*
* @author Jason Lam <hide@address.com>
* @version 1.0.7
* @access public
* @copyright Released under the LGPL License, see COPYING file
*
* @Revision
* 04/16/2003 Jason Lam Added SortDirList Function
*/
class FileManager {
/**
* _tempDir
*
* @var temporary dir the upload file
* @access private
*/
var $_tempDir;
/**
* _baseDir
*
* @var To hold the base root of the user, its assumed there
* is more then one user using the phpWebFileManager
* For example directory structure may look like this
* on Linux system with 3 users
* /usr/local/public/web/users/johndoe
* /usr/local/public/web/users/jasonlam
* /usr/local/public/web/users/janedoe
* The _baseDir would then be /usr/local/public/web/users
*
* @access private
*/
var $_baseDir;
/**
* _webRoot
*
* @var To hold the base directory of users from WEB perspective not
* the same as baseDir, NOT the absolute directory like
* /usr/local/public/web/users/johndoe
* instead the relative directory in this case if the public web directory
* starts at web then this would be the $_webRoot
* It is basiclly the parent directories above the members directory
* ie: http://johndoe.youdomain.com/
*
* The exact variable contents would be ---> "/web"
*
* This was added to essentially handle the possibility of downloading
* any the files in the members directory as well as export file created
* by the export function.
*
* @access private
*/
var $_webRoot;
/**
* _domainName
*
* @var To hold the suffix FQDN ie: 'sourcefore.net'. See getSiteName would return
* www.membername.sourceforge.net, otherwise if left blank getSiteName would only
* return 'membername'
* @access private
*/
var $_domainName = "";
/**
* _member
*
* @var To hold member name
* @access private
*/
var $_member = "";
/**
* _memberDir
*
* @var To the full path of where the member is current at
* this is different from _memberDirRoot because the user
* is allowed to make one level subdirectories.
* @access private
*/
var $_memberDir;
/**
* _memberDirRoot
*
* @var To hold member's home root directory
* @access private
*/
var $_memberDirRoot;
/**
* _memberSubDir
*
* @var To hold member's current sub directory
* @access private
*/
var $_memberSubDir;
/**
* _isSubDir
*
* @var To determine if the directory is a subdirectory or not
* @access private
*/
var $_isSubDir;
/**
* _fileCount
*
* @var total file count
* @access private
*/
var $_fileCount = 0;
/*
* _displayColumnCount
*
* @var total number columns displayed
* @access private
*
*/
var $_displayColumnCount = 3; // Name, Last Modified, Size
/*
* _maxSubDirCount
*
* If set at zero meaning unlimited
* @var total number subDir allowed
* @access private
*/
var $_maxSubDirCount = 0;
/*
* _isIgnoreCaseSorting
*
* if set to true then ignore case when sorting name column
* @var boolean true or false
* @access private
*/
var $_isIgnoreCaseSortName = true; // default set to true
/*
* _invalidExtensions
*
* To hold invalid extensions
* @var array of strings
* @access private
*/
var $_invalidExtensions = array ("php","shtml","php3","inc","class","jsp","asp","xml","chm","exe");
/*
* _locale
*
* @var locale Class
* @access private
*/
var $_locale;
/*
* _findResult
*
* @var To hold find matches in an array, needs to be class variable instead
* local method variable because recursion is being used.
* @access private
*/
var $_findResult = array();
var $_findCount;
var $_findText;
var $_findMatchCase = false;
var $_findExact = false;
/*
* _isFirewall and _externaURL
*
* @var Used for manual override of url - for people using the app behind a firewall
* previsous version would only grab your local IP using $_SERVER["SERVER_ADDR"]
* @access private
*/
var $_isFirewall = false;
var $_externalURL = "";
/**
* !Constructor
*
* @param member name,, temp dir, base directory, locale this makes filemanager tightly couple to locale
* the trade off is mult-language support
* @return none
* @access public
*/
function FileManager($member,$tempDir,$baseDir,$locale,$webRoot) {
$this->_member = $member;
$this->_tempDir = $tempDir;
$this->_baseDir = $baseDir . "/";
$this->_memberDir = $this->_baseDir . $member;
$this->_memberDirRoot = $this->_baseDir . $member;
$this->_isSubDir = false;
$this->_locale = $locale;
$this->_webRoot = $webRoot;
}
function isMemberDirExist() {
if (file_exists($this->_memberDir))
return true;
else
return false;
}
/**
* Get the current directory list based what the current directory is
*
* @param subdirectory <optional> otherwise assume root
* @return none
* @access public
*/
function getDirList($subDir = "") {
$directoryList = array();
if ( (strlen(trim($subDir)) > 0) && (file_exists($this->_memberDir . "/" . $subDir)) && (is_dir($this->_memberDir . "/" . $subDir)) ) {
$this->_memberDir = $this->_memberDir . "/" . $subDir;
$this->_memberSubDir = $subDir;
$this->_isSubDir = true;
} else {
$this->_isSubDir = false;
}
$d = dir($this->_memberDir);
$count = 0;
while (false !== ($entry = $d->read())) {
// Extra precaution do not list php, xml, . and ..
// Modify to your preference
if ( (!stristr($entry,".php")) && (!strstr($entry,".xml")) && (strcmp($entry,".")!=0) && (strcmp($entry,"..")!=0) ) {
$directoryList[$count]["name"] = $entry;
$directoryList[$count]["lastmod"] = $this->_getLastModified($this->_memberDir . "/" . $entry);
$directoryList[$count]["size"] = (int) $this->_getSize($this->_memberDir . "/" . $entry);
if (is_dir($this->_memberDir . "/" . $entry))
$directoryList[$count]["isDir"] = true;
else
$directoryList[$count]["isDir"] = false;
$count++;
}
}
$d->close();
$this->_fileCount = $count;
return $directoryList;
}
/*
* Sort Given DirectoryList
*
* @param $directoryList <required>, column to sort <required>
* @return sorted $directoryList
* @access public
*
*/
function sortDirList($dirList,$sortCol,$isASC=true) {
$result[0] = true;
$result[1] = ""; // dual purpose if $result[0] is false then $result[1] will hold
// the error message otherwise it will hold the sort $directoryList
// check if sort column is numeric
if (!$this->_isDigit($sortCol)) {
$result[0] = false;
$result[1] = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_SORT_INVALID_COL);
return $result;
}
// check if sort column is existing column
if ($sortCol > $this->_displayColumnCount || $sortCol < 1) {
$result[0] = false;
$result[1] = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_SORT_INVALID_COL);
return $result;
}
if ($result[0]) {
// The core sorting is done by using PHP built in function array_multisort
// Becuase the data is row based not column based we need to convert
// the data appropriately, yes this is somewhat inefficient but should
// be okay with directories with few hundred or less files and directories.
// Should be okay with few thousand. Sorta of an assumption here that
// most average users won't have thousands of directories and files under
// ther root directory. This was done instead of code re-work to minimize
// regression testing and introduction of new bugs.
$colToSort = $sortCol - 1; // index starts from 0 need to minus 1 on web page columns start from 1
// this was done because the $_GET treats digit 0 as empty
$dirListCount = count($dirList);
$dirListTemp = $this->_rowToColMode($dirList,$dirListCount);
if ($colToSort == 0 && $this->_isIgnoreCaseSortName) {
$dirListTemp["namelowercase"] = $this->_arrayToLower($dirListTemp["name"],$dirListCount);
}
if ($isASC) {
switch($colToSort) {
case 0:
if ($this->_isIgnoreCaseSortName)
array_multisort($dirListTemp["namelowercase"],SORT_ASC, SORT_STRING,$dirListTemp["name"],$dirListTemp["lastmod"],$dirListTemp["size"],$dirListTemp["isDir"]);
else
array_multisort($dirListTemp["name"],SORT_ASC, SORT_STRING,$dirListTemp["lastmod"],$dirListTemp["size"],$dirListTemp["isDir"]);
break;
case 1: array_multisort($dirListTemp["lastmod"],SORT_ASC,$dirListTemp["name"],$dirListTemp["size"],$dirListTemp["isDir"]); break;
case 2: array_multisort($dirListTemp["size"],SORT_ASC,SORT_NUMERIC,$dirListTemp["lastmod"],$dirListTemp["name"],$dirListTemp["isDir"]); break;
};
} else {
switch($colToSort) {
case 0:
if ($this->_isIgnoreCaseSortName)
array_multisort($dirListTemp["namelowercase"],SORT_DESC, SORT_STRING,$dirListTemp["name"],$dirListTemp["lastmod"],$dirListTemp["size"],$dirListTemp["isDir"]);
else
array_multisort($dirListTemp["name"],SORT_DESC, SORT_STRING,$dirListTemp["lastmod"],$dirListTemp["size"],$dirListTemp["isDir"]);
break;
case 1: array_multisort($dirListTemp["lastmod"],SORT_DESC,$dirListTemp["name"],$dirListTemp["size"],$dirListTemp["isDir"]); break;
case 2: array_multisort($dirListTemp["size"],SORT_DESC,SORT_NUMERIC,$dirListTemp["lastmod"],$dirListTemp["name"],$dirListTemp["isDir"]); break;
};
}
$dirListTemp = $this->_colToRowMode($dirListTemp,$dirListCount);
$dirList = $dirListTemp;
}
$result[1] = $dirList; // trick here to access list you need access result as triple array
// ie: $result[1][0]["name"] to get first record file name
return $result;
}
/*
* _arryToLower - convert array of strings to lower case
*
* @param array of string values
* @return array with all its values lower case
* @access private
*
*/
function _arrayToLower($arrayValues,$arraySize) {
for ($i=0;$i<$arraySize;$i++) {
$arrayValues[$i] = strtolower($arrayValues[$i]);
}
return $arrayValues;
}
/*
* Convert $dirList from row based to column based
*
* @param $dirList as row based <required>, record/row count <required>
* @return $dirList as column based
* @access private
*
*/
function _rowToColMode($dirList,$recCount) {
$result = array();
for ($i=0; $i<$recCount; $i++) {
$results["name"][$i] = $dirList[$i]["name"];
$results["lastmod"][$i] = $dirList[$i]["lastmod"];
$results["size"][$i] = $dirList[$i]["size"];
$results["isDir"][$i] = $dirList[$i]["isDir"];
}
return $results;
}
/*
* Convert $dirList from column based to row based
*
* @param $dirList as column based<required>, record/row count <required>
* @return $dirList as row based
* @access private
*
*/
function _colToRowMode($dirList,$recCount) {
$result = array();
for ($i=0; $i<$recCount; $i++) {
$results[$i]["name"] = $dirList["name"][$i];
$results[$i]["lastmod"] = $dirList["lastmod"][$i];
$results[$i]["size"] = $dirList["size"][$i];
$results[$i]["isDir"] = $dirList["isDir"][$i];
}
return $results;
}
/**
* Copy specified file
*
* @param src file, dest file
* @return return result message
* @access public
*/
function copyFile($oldFileName,$newFileName) {
$result = "";
if ($this->_validateExtension($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_INVALID_EXT) . "<i>" . $this->_getExtAsString() . "</i><br>";
} else {
if (!is_dir($this->_memberDir . "/" . $oldFileName)) {
if ($this->_validateFileName($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_INVALID_NAME);
} else if (strcmp($this->_memberDir . "/" . $oldFileName,$this->_memberDir . "/" . $newFileName)==0) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_ALREADY_EXISTS) . "<br>";
} else if ($this->_validateFileNameExist($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_ALREADY_EXISTS) . "<br>";
} else {
if (copy ($this->_memberDir . "/" . $oldFileName,$this->_memberDir . "/" . $newFileName))
$result = $oldFileName . $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_SUCCESS) . $newFileName . "<br>";
else
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_FAILED) . $oldFileName . "<br>";
}
} else {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_INVALID_DIR) . "<br>";
}
}
return $result;
}
/**
* Rename specified file
*
* @param src file, dest file
* @return string , return result message
* @access public
*/
function renameFile($oldFileName, $newFileName) {
$result = "";
if ($this->_validateFileName($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_INVALID_NAME);
} else if ($this->_validateExtension($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_INVALID_EXT) . "<i>" . $this->_getExtAsString() . "</i><br>";
} else if ($this->_validateFileNameExist($newFileName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_RENAME_ALREADY_EXISTS) . ", " .$newFileName . "<br>";
} else {
if (strcmp($this->_memberDir . "/" . $oldFileName,$this->_memberDir . "/" . $newFileName)==0) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_RENAME_ALREADY_EXISTS) . ", " .$newFileName . "<br>";
} else {
if (rename ($this->_memberDir . "/" . $oldFileName,$this->_memberDir . "/" . $newFileName))
$result = $oldFileName . $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_RENAME_SUCCESS) . $newFileName . "<br>";
else
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_COPY_FAILED) . " " . $oldFileName . "<br>";
}
}
return $result;
}
/**
* Delete specified file
*
* @param file to delete
* @return return result message
* @access public
*/
function deleteFile($filename) {
$result = "";
if (is_dir($this->_memberDir . "/" . $filename)) {
$result = $this->deleteDirectory($filename);
} else {
if(file_exists($this->_memberDir . "/" . $filename)) {
chmod($this->_memberDir . "/" . $filename,0777);
unlink($this->_memberDir . "/" . $filename);
$result = $filename . $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_DEL_SUCCESS) . "<br>";
} else {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_DEL_FAILED) . $filename . "<br>";
}
}
return $result;
}
/**
* Delete specified Directory
* Recursively delete everything in the directory
* @param directory to delete
* @return string, result message
* @access public
*/
function deleteDirectory($Dir){
$result = "";
if ($handle = @opendir($this->_memberDir . "/" . $Dir)) {
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
if (is_dir($this->_memberDir . "/" . $Dir . "/" . $file)){
$this->deleteDirectory($Dir . "/" . $file);
if (file_exists($this->_memberDir . "/" . $Dir . "/" . $file)) {
chmod($this->_memberDir . "/" . $Dir . "/" . $file,0777);
rmdir($this->_memberDir . "/" . $Dir . "/" . $file); //remove child dir
}
} else {
//echo "file<br>";
if (file_exists($this->_memberDir . "/" . $Dir . "/" . $file)) {
chmod($this->_memberDir . "/" . $Dir . "/" . $file,0777);
unlink($this->_memberDir . "/" . $Dir . "/" . $file); // remove a file
}
}
}
}
}
@closedir($handle);
// delete original dir this assumes its empty, should be empty
// the above code takes care of this
if(file_exists($this->_memberDir . "/" . $Dir . "/" . $file)) {
chmod($this->_memberDir . "/" . $Dir,0777);
rmdir($this->_memberDir . "/" . $Dir); //remove this directory
}
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_DEL_FOLDER) . "<i>" . $Dir . "</i>" . $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_DEL_SUCCESS) . "<br>";
return $result;
}
/**
* Create specified Directory
*
* @param directory to create
* @return string, result message
* @access public
*/
function makeDirectory($dirName,$subDir) {
$result = "";
$dirName = trim($dirName);
$currSubDirCount = count( preg_split("/[\W]+/", $subDir) );
if (strstr($dirName," ")) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_MKDIR_INVALID_NAME) . "<i>" .$dirName. "</i><br>";
} elseif (!$this->_validateAlphaNumericOnly($dirName)) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_MKDIR_INVALID_NAME) . "<i>" .$dirName. "</i><br>";
} else if ( file_exists($this->_memberDir . "/" . $dirName) && !is_file( $this->_memberDir . "/" .$dirName ) ) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_MKDIR_ALREADY_EXISTS) . "<i>" .$dirName. "</i><br>";
} if ($this->_maxSubDirCount > 0 && $currSubDirCount >= $this->_maxSubDirCount) {
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_MKDIR_CHAINED) . "<i>" .$dirName. "</i><br>";
}
if (empty($result)) {
mkdir ($this->_memberDir . "/" . $dirName, 0777);
$result = $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_MKDIR_SUCCESS) . "<i>" .$dirName. "</i><br>";
}
return $result;
}
/**
* Upload Files
*
* @param Array of files
* @return string, result message
* @access public
*/
function uploadFiles($userfile,$userfile_name,$userfile_size) {
$result = "";
$fileCount = count($userfile);
for ($i=0;$i<$fileCount;$i++) {
if ( $userfile_size[$i] > 0 ) {
$fileUpload = new FileUpload($userfile[$i],$userfile_size[$i],$userfile_name[$i],$this->_memberDir,$this->_tempDir);
$fileUpload->setValidExt($this->_invalidExtensions);
$isValid = true;
if (!$fileUpload->validateFileType()) {
$isValid = false;
} elseif (!$fileUpload->validateFileSize()) {
$isValid = false;
} elseif (!$fileUpload->validateDirSize()) {
$isValid = false;
}
if ($isValid) {
$fileUpload->upload();
$result .= $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_UPLOAD_SUCCESS) . "<i>" .$userfile_name[$i]. "</i><br>";
} else {
$result .= $this->_locale->getString(LID_TYPE_MSG_FM,LID_MSG_FM_UPLOAD_FAILED) . "<i>" .$userfile_name[$i]. "</i><br>";
}
} // end if check if idx has file
} // end for
return $result;
}
/**
* processFind - recursion is used to traverse through the directories
*
* @param SubDirectory ( to being search from that directory and downwards
* @return none
* @access public
*/
function processFind($subDir="") {
$theDir = $this->_memberDir . "/" . $subDir;
if (strlen($this->_findText)>0) {
if ($handle = @opendir($theDir)) {
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
if (is_dir($theDir . "/" . $file)){
$this->_matchFind($file,$subDir,true);
if (strlen($subDir) > 0) {
$this->processFind($subDir . "/" . $file);
} else {
$this->processFind($file);
}
} else {
$this->_matchFind($file,$subDir,false);
}
}
}
}
@closedir($handle);
}
}
/**
* _matchFind - Determine if match is found if so add to the findResult array
*
* @param file or directory name
* @return none
* @access private
*/
function _matchFind($file,$path,$isDir) {
if ($this->_findMatchCase) {
if ($this->_findExact) {
if (strcmp($file,$this->_findText)==0) {
//$this->_findResult[$this->_findCount] = $file;
$this->_findResult[$this->_findCount]["file"] = $file;
$this->_findResult[$this->_findCount]["path"] = $path;
$this->_findResult[$this->_findCount]["isDir"] = $isDir;
$this->_findCount++;
}
} else {
if (strstr($file,$this->_findText)) {
$this->_findResult[$this->_findCount]["file"] = $file;
$this->_findResult[$this->_findCount]["path"] = $path;
$this->_findResult[$this->_findCount]["isDir"] = $isDir;
$this->_findCount++;
}
}
} else {
if ($this->_findExact) {
if (strcmp(strtolower($file),strtolower($this->_findText))==0) {
$this->_findResult[$this->_findCount]["file"] = $file;
$this->_findResult[$this->_findCount]["path"] = $path;
$this->_findResult[$this->_findCount]["isDir"] = $isDir;
$this->_findCount++;
}
} else {
if (stristr($file,$this->_findText)) {
$this->_findResult[$this->_findCount]["file"] = $file;
$this->_findResult[$this->_findCount]["path"] = $path;
$this->_findResult[$this->_findCount]["isDir"] = $isDir;
$this->_findCount++;
}
}
}
}
/**
* initFind - initialize / reset Find
*
* @param file or directory name
* @return none
* @access public
*/
function initFind($findText,$findMatchCase,$findExact) {
$this->_findCount = 0;
$this->_findResult = array();
$this->_findText = $findText;
$this->_findMatchCase = $findMatchCase;
$this->_findExact = $findExact;
}
/**
* getFindResult - simple getter for findResult array, contains all matches
* according to current find criteria
*
* @param none
* @return array of file or directory names
* @access public
*/
function getFindResult() {
return $this->_findResult;
}
/**
* Get Total size of all the directories
*
* @param none
* @return directory size
* @access public
*/
function getTotalSizeUsed() {
return $this->_dirsize($this->_memberDirRoot);
}
/**
* Get directory size for specified directory
* Calculate the size of files in $dir, (it descends recursively into other dirs)
* @param subdirectory
* @return size
* @access public
*/
function _dirsize($dir) {
$dh = opendir($dir);
$size = 0;
while (($file = readdir($dh)) !== false)
if ($file != "." and $file != "..") {
$path = $dir."/".$file;
if (is_dir($path))
$size += $this->_dirsize($path);
elseif (is_file($path))
$size += filesize($path);
}
closedir($dh);
return $size;
}
/**
* Get last modified time for file
* @param file
* @return modified time
* @access private
*/
function _getLastModified ($theFile) {
$filemod = filemtime($theFile);
$filemodtime = date("F j Y h:i:s A", $filemod);
return $filemodtime;
}
/**
* Get file size
* @param file
* @return file size
* @access private
*/
function _getSize($theFile) {
return filesize ($theFile);
}
/**
* Validate String to see if only contains letters and or digits
* @param string
* @return boolean
* @access private
*/
function _validateAlphaNumericOnly ($theString) {
$result = false;
if (preg_match('/^[a-zA-Z0-9]+$/',$theString )) {
$result = true;
}
return $result;
}
/**
* Validate filename only has char, numeric, underscore and/or periods
* @param valid filename
* @return boolean, returns true if its invalid
* @access private
*/
function _validateFileName($thefilename) {
$result = false;
if (!preg_match('/^[a-zA-Z0-9_.]+$/',$thefilename)) {
$result = true;
}
return $result;
}
/**
* Validate filename if it already exists in the directory including
* @param valid filename
* @return boolean, returns true if its invalid
* @access private
*/
function _validateFileNameExist($thefilename) {
$dirList = $this->getDirList();
$listMax = $this->_fileCount;
$result = false;
for ($i=0; $i<$listMax; $i++) {
if ( strcmp($dirList[$i]["name"],$thefilename)==0 ) {
$result = true;
break;
}
}
return $result;
}
/**
* Validate filename extensions
* @param valid filename
* @return boolean
* @access private
*/
function _validateExtension($newFileName) {
$len = count($this->_invalidExtensions);
for ($i=0; $i<$len; $i++) {
if (stristr($newFileName,"." . $this->_invalidExtensions[$i])) {
return true;
}
}
return false;
}
/**
* Get name of member directory
* This is bias , i made assuming your membership structure would like
* www.membername.yourfqdn.com, obvisously needs to be changed
* If yours is different, ie: www.yourfqdn.com/membername/
* @param valid filename
* @return boolean
* @access private
*/
function getSiteName() {
if (strlen($this->_domainName) > 0)
return "www." . $this->_member . "." . $this->_domainName;
else
return $this->_member;
}
/*
* _isDigit - Simply validate value contains only numeric values
* had problems using is_int and is_numeric
* @param string value
* @return true or false
* @access private
*
*/
function _isDigit($value) {
if (!preg_match('/^[0-9]+$/',$value ))
return false;
return true;
}
function _getExtAsString() {
$len = count($this->_invalidExtensions);
$ext = "";
for($i=0; $i<$len; $i++) {
$ext .= $this->_invalidExtensions[$i] . ",";
}
return substr($ext,0,strlen($ext)-1);
}
function exportFile($filename,$compress_cfg) {
$result = array();
$result[0] = true;
$result[1] = "";
if (!preg_match('/^[a-zA-Z0-9_.]+$/',$filename)) {
$result[0] = false;
$result[1] = "Invalid File Name, only letters and number allowed";
} else {
//include_once("lib/compress.class.php");
$compress_cfg["dir"] = $this->_memberDir;
$compress_cfg["dir_temp"] = $this->_tempDir;
$compress = &Compress::singleton("tgz",$compress_cfg);
$compress->compress($filename);
}
return $result;
}
function importFile($filename,$compress_cfg,$userfile) {
$result = array();
$result[0] = true;
$result[1] = "";
//if (!preg_match('/^[a-zA-Z0-9_.]+$/',$filename)) {
// $result[0] = false;
// $result[1] = "Invalid File Name, only letters and number allowed";
//} else {
// Do Import Here
//$fileUpload = new FileUpload($userfile[$i],$userfile_size[$i],$userfile_name[$i],$this->_memberDir,$this->_tempDir);
// "Temp Name: " . $userfile["tmp_name"] . "<br>";
//echo "Name: " . $userfile["name"] . "<br>";
//echo "File Size: " . $userfile["size"] . "<br>";
$tempIdx = strrpos($userfile["tmp_name"],"\\");
if ($tempIdx === false)
$tempIdx = strrpos($userfile["tmp_name"],"/");
$tempIdx;
if ($tempIdx === false) {
$tmp_filename = $userfile["tmp_name"];
} else {
$tmp_filename = substr($userfile["tmp_name"],$tempIdx+1);
$tmp_dir = substr($userfile["tmp_name"],0,$tempIdx+1);
}
$filename = $userfile["name"];
$compress_cfg["dir"] = $this->_memberDir;
$compress_cfg["dir_temp"] = $tmp_dir;
$compress = &Compress::singleton("tgz",$compress_cfg);
$compress->decompress($filename,$tmp_filename);
//}
return $result;
}
function getFileCount() { return $this->_fileCount; }
function getIsSubDir() { return $this->_isSubDir; }
function getSubDir() { return $this->_memberSubDir; }
function getMember() { return $this->_member; }
function getBaseDir() { return $this->_baseDir; }
function getWebRoot() { return $this->_webRoot; }
function getMemberDir() { return $this->_memberDir; }
function getIsFirewall() { return $this->_isFirewall; }
function getExternalURL() { return $this->_externalURL; }
function setDomainName($domainName) { $this->_domainName = $domainName; }
function setIsSubDir($isSubDir) { $this->_isSubDir = $isSubDir; }
function setMaxChainSubDir($maxSubDirCount) { $this->_maxSubDirCount = $maxSubDirCount; }
function setIgnoreCaseNameSort($isIgnoreCaseSortName) { $this->_isIgnoreCaseSortName = $isIgnoreCaseSortName; }
function setInvalidExt($invalidExtensions) { $this->_invalidExtensions = $invalidExtensions; }
function setIsFirewall($isFirewall) { $this->_isFirewall = $isFirewall; }
function setExternalURL($externalURL) {
// validation needs to be put in val
$this->_externalURL = $externalURL;
}
}
?>