From 97520cbb1fcdb545cb829e69639c5a1548a956ef Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Thu, 29 Jun 2017 11:32:18 +0200 Subject: [PATCH] added config option for temporary directory; closes #34 --- ifm.php | 17 +++++++++++++---- src/config.php | 7 +++++++ src/main.php | 10 ++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ifm.php b/ifm.php index ca4df6f..4fe3dca 100644 --- a/ifm.php +++ b/ifm.php @@ -70,6 +70,13 @@ class IFMConfig { const root_dir = ""; const defaulttimezone = "Europe/Berlin"; // set default timezone + /** + * Temp directory for zip files + * + * Default is the upload_tmp_dir which is set in the php.ini, but you may also set an different path + */ + const tmp_dir = ""; + // development tools const ajaxrequest = 1; // formular to perform an ajax request @@ -1356,7 +1363,7 @@ ifm.init(); if( ! is_dir( realpath( IFMConfig::root_dir ) ) || ! is_readable( realpath( IFMConfig::root_dir ) ) ) die( "Cannot access root_dir."); else - chdir( IFMConfig::root_dir ); + chdir( realpath( IFMConfig::root_dir ) ); if ( ! isset($_REQUEST['api']) ) { $this->getApplication(); } else { @@ -1719,7 +1726,7 @@ ifm.init(); echo json_encode( array( "status" => "ERROR", "message" => "Filename not allowed" ) ); else { unset( $zip ); - $dfile = uniqid( "ifm-tmp-" ) . ".zip"; // temporary filename + $dfile = $this->pathCombine( IFMConfig::tmp_dir, uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename try { IFMZip::create_zip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) ); if( $d['filename'] == "." ) { @@ -1962,10 +1969,12 @@ ifm.init(); // combines two parts to a valid path private function pathCombine( $a, $b ) { - if( $a=="" && $b=="" ) + if( trim( $a ) == "" && trim( $b ) == "" ) return ""; + elseif( trim( $a ) == "" ) + return ltrim( $b, '/' ); else - return ltrim( rtrim( $a, '/' ) . '/' . ltrim( $b, '/' ), '/' ); + return rtrim( $a, '/' ) . '/' . ltrim( $b, '/' ); } // check if filename is allowed diff --git a/src/config.php b/src/config.php index 8fc1a34..8c0ed61 100644 --- a/src/config.php +++ b/src/config.php @@ -70,6 +70,13 @@ class IFMConfig { const root_dir = ""; const defaulttimezone = "Europe/Berlin"; // set default timezone + /** + * Temp directory for zip files + * + * Default is the upload_tmp_dir which is set in the php.ini, but you may also set an different path + */ + const tmp_dir = ""; + // development tools const ajaxrequest = 1; // formular to perform an ajax request diff --git a/src/main.php b/src/main.php index 3ad1221..eae3cab 100644 --- a/src/main.php +++ b/src/main.php @@ -164,7 +164,7 @@ class IFM { if( ! is_dir( realpath( IFMConfig::root_dir ) ) || ! is_readable( realpath( IFMConfig::root_dir ) ) ) die( "Cannot access root_dir."); else - chdir( IFMConfig::root_dir ); + chdir( realpath( IFMConfig::root_dir ) ); if ( ! isset($_REQUEST['api']) ) { $this->getApplication(); } else { @@ -527,7 +527,7 @@ class IFM { echo json_encode( array( "status" => "ERROR", "message" => "Filename not allowed" ) ); else { unset( $zip ); - $dfile = uniqid( "ifm-tmp-" ) . ".zip"; // temporary filename + $dfile = $this->pathCombine( IFMConfig::tmp_dir, uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename try { IFMZip::create_zip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) ); if( $d['filename'] == "." ) { @@ -770,10 +770,12 @@ class IFM { // combines two parts to a valid path private function pathCombine( $a, $b ) { - if( $a=="" && $b=="" ) + if( trim( $a ) == "" && trim( $b ) == "" ) return ""; + elseif( trim( $a ) == "" ) + return ltrim( $b, '/' ); else - return ltrim( rtrim( $a, '/' ) . '/' . ltrim( $b, '/' ), '/' ); + return rtrim( $a, '/' ) . '/' . ltrim( $b, '/' ); } // check if filename is allowed