Source for file FileTree.php
Documentation is available at FileTree.php
* Class to read the disc and build a JSON array from the files.
* This is based on documentation found at:
* http://aariadne.com/filetree/
* @author Julien-Samuel Lacroix
* @copyright 2010, Mapgears inc
* @license http://www.geoprisma.org/license BSD License
* @link http://www.geoprisma.org
* Class to read the disc and build a JSON array from the files.
* This is based on documentation found at:
* http://aariadne.com/filetree/
* @author Julien-Samuel Lacroix
* @param string $pstrRootPath based path of the listing
if ($pstrRootPath &&
is_dir($pstrRootPath))
$this->setRootPath($pstrRootPath);
* Read the content of a file path and returns a JSON object of it
* @param string $pstrFilePath Directory to read
* @param array $pobjArrayFileList Array of files
* @param array $pobjArrayResources Array of resources
$pobjArrayFileList=
array(),
$pobjArrayResources=
array()
if (count($pobjArrayFileList) <=
0)
$objArrayDirectoryToJSON =
array();
foreach ($pobjArrayFileList as $strEntry)
if (substr($strEntry, 0, 1) !=
'.')
$objArrayDirectoryToJSON[] =
$this->getFileJSON($strFilePath, $strEntry, $pobjArrayResources);
return '['.
implode(',', $objArrayDirectoryToJSON).
']';
* Read the content of a file path and return it to the browser.
* @param string $pstrFilePath Path of the file to download
* @param bool $pbForceDownload Whether to force downloading the file or
public function download($pstrFilePath, $pbForceDownload =
true)
if ($pbForceDownload !==
false)
header("Content-type: application/force-download");
header("Content-disposition: attachment; filename=\"".
basename($strFilePath).
"\"");
$objArrayPathParts =
pathinfo($strFilePath);
$strExt =
strtolower($objArrayPathParts["extension"]);
// Determine Content Type
$strCType=
"application/pdf";
$strCType=
"application/msword";
$strCType=
"application/vnd.ms-excel";
$strCType=
"application/vnd.ms-powerpoint";
default:
$strCType=
"application/force-download";
header("Content-type: $strCType");
header("Content-disposition: inline; filename=\"".
basename($strFilePath).
"\"");
header("Content-Transfer-Encoding: Binary");
* @param string $pstrPath Path of the file
* @param string $pstrFile Name of the file
* @param array $pobjArrayResources Array of resources
public function getFileJSON($pstrPath, $pstrFile, $pobjArrayResources)
if (substr($pstrPath, -
1) !=
'/')
$objFileDescription =
array(
'leaf' =>
(is_dir($pstrPath.
$pstrFile)?
false:
true),
'qtip' =>
(is_file($pstrPath.
$pstrFile)?
'Size: '.
filesize($pstrPath.
$pstrFile).
' bytes':
'')
if (is_dir($pstrPath.
$pstrFile))
$objFileDescription['cls'] =
'folder';
if (isset
($pobjArrayResources[$pstrFile]))
$objFileDescription['osmresource'] =
$pobjArrayResources[$pstrFile];
* @param string $pstrFilePath Path of the file
$objArrayFileList =
array();
return $objArrayFileList;
$objDirectory =
dir($strFilePath);
while (false !==
($strEntry =
$objDirectory->read()))
if (substr($strEntry, 0, 1) !=
'.')
$objArrayFileList[] =
$strEntry;
return $objArrayFileList;
private function getRootPath()
* @param string $pstrRootPath The root path to set.
private function setRootPath($pstrRootPath)
if (substr($pstrRootPath, -
1) ==
'/')
$pstrRootPath =
substr($pstrRootPath, 0, -
1);
* Returns current uploaded item
return $_FILES['x-filename'];
* Upload a file using current uploaded item.
* @param string $pstrBasePath The bae path of the file to upload.
public function upload($pstrBasePath)
$strBasePath =
realpath($this->getRootPath().
'/'.
$pstrBasePath);
$strFilePath =
$strBasePath.
'/'.
$objArrayUploadedItem['name'];
// do not upload if file already exists
'errors' =>
array("message" =>
"File already exists")
if ($objResponse ===
false
&&
$objArrayUploadedItem['error'] !==
UPLOAD_ERR_OK
$objArrayUploadedItem['error']
if ($objResponse ===
false)
$objArrayUploadedItem['tmp_name'],
$objResponse =
array('success' =>
true);
'errors' =>
array("message" =>
"Could not upload file")
* @param string $pstrPath The path of the directory to create
$strPath =
$this->getRootPath().
'/'.
$pstrPath;
$objResponse =
array('success' =>
true);
'errors' =>
array("error" =>
"Could not create directory")
* Return the upload error message using the error code.
* @param integer $piErrorCode The error code returned
case UPLOAD_ERR_INI_SIZE:
$strMessage =
'The uploaded file exceeds the upload_max_filesize directive in php.ini';
case UPLOAD_ERR_FORM_SIZE:
$strMessage =
'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
$strMessage =
'The uploaded file was only partially uploaded';
$strMessage =
'No file was uploaded';
case UPLOAD_ERR_NO_TMP_DIR:
$strMessage =
'Missing a temporary folder';
case UPLOAD_ERR_CANT_WRITE:
$strMessage =
'Failed to write file to disk';
case UPLOAD_ERR_EXTENSION:
$strMessage =
'File upload stopped by extension';
$strMessage =
'Unknown upload error';
Documentation generated on Mon, 20 Feb 2012 13:46:18 -0500 by phpDocumentor 1.4.1