Page 1 of 1

Image and File upload

Posted: 2011-07-01 13:38
by Fred
Like I said in a different post, I found an image and file up loader that can be integrated with tinymce as a replacement for KTML
Ajax File/Image Manager by phpletter

I had one issue and that was that the KTML uploader supports the dynamic creation of folders for different members.

A hack to allow the Ajax File / Image Manager do the same.
Things to consider.
  • 1. Different user needs different folders, dynamically created if it doesn't exist.
    2. Depending on what page the user is on, you might need different folders.
Locate config.base.php in the ajaxfilemanager/inc folder

First we need to find out what page we are on.

Code: Select all

// Check what page we are on
// My current code   
$req_uri = $_SESSION['page'];
$check = 'article_update.php';
$page = strpos($req_uri, $check);
Search for the following lines:

Code: Select all

	define('CONFIG_SYS_DEFAULT_PATH', '../uploaded/'); //accept relative path only
	define('CONFIG_SYS_ROOT_PATH', '../uploaded/');	//accept relative path only
and replace with

Code: Select all

if ($page !== false) { // Set default upload settings for the articles in member section
   // Check if folder exists
   if (!is_dir('../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'')) {
   mkdir('../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'', 0755); // Create the folder and set permissions
   }
   // Continue setting the default folders
   define('CONFIG_SYS_DEFAULT_PATH', '../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'/'); //accept relative path only
   define('CONFIG_SYS_ROOT_PATH', '../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'/');   //accept relative path only
}   else { // Use default settings if not members article pages
   define('CONFIG_SYS_DEFAULT_PATH', '../../../../uploads/media/'); //accept relative path only
   define('CONFIG_SYS_ROOT_PATH', '../../../../uploads/media/');   //accept relative path only
}
So your complete code that you need to insert / replace looks like this

Code: Select all

// Check what page we are on      
$req_uri = $_SESSION['page'];
$check = 'article_update.php';
$page = strpos($req_uri, $check);

if ($page !== false) { // Set default upload settings for the articles in member section
   // Check if folder exists and create
   if (!is_dir('../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'')) {
   mkdir('../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'', 0755); // Create the folder and set permissions
   }
   // Continue setting the default folders
   define('CONFIG_SYS_DEFAULT_PATH', '../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'/'); //accept relative path only
   define('CONFIG_SYS_ROOT_PATH', '../../../../uploads/media/Members/'.$_SESSION['kt_login_id'].'/');   //accept relative path only
}   else { // Use default settings if not members article pages
   define('CONFIG_SYS_DEFAULT_PATH', '../../../../uploads/media/'); //accept relative path only
   define('CONFIG_SYS_ROOT_PATH', '../../../../uploads/media/');   //accept relative path only
}
Obviously adjust the folders and variables to suit your needs.