CKEditor Folder by User in imgupload and imgbrowse

byronclunz
Posts: 6

CKEditor Folder by User in imgupload and imgbrowse

I've managed to get imgbrowse and imgupload working with ckeditor 4.5.4! A question though: when uploading images to the server, can the user create a new directory? If so how?
- I would like to give multiple users each their own directory.

Admin
Hello,
To create a new directory, you can use this code in php:

Code: Select all

mkdir('/path/to/my_dir', 0755);

- But, the question is: how do you pass the name of the new directory for each user to the imgupload.php script? Do you have the name stored into a session?

If you want to have the folder according to the user name, and the username is stored into a session, for example: $_SESSION['user'], add this code to the beginning of the "imgupload.php" file (after <?php):

Code: Select all

session_start();

And replace this line of code:

Code: Select all

$upload_dir = trim($upload_dir, '/') .'/';

With this code:

Code: Select all

$upload_dir = trim($upload_dir, '/') .'/';
if(isset(
$_SESSION['user'])){
  $upload_dir = $upload_dir .$_SESSION['user'] .'/';
  //if folder $upload_dir not exists, creates it with 0755 CHMOD permissions
  if(!is_dir($_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir)) mkdir($_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir, 0755);
}

byronclunz
Great! That works. Almost there... now how can I modify imgbrowse so that it looks (only) in the same directory?

Admin
Try this:
1. Add session_start(); to the beginning of the "imgbrowse.php" file (in "ckeditor/plugins/imgbrowse/" directory).
2. Replace these 2 lines of code:

Code: Select all

if(isset($_POST['imgroot'])) $this->root = trim(strip_tags($_POST['imgroot']));
$this->root = trim($this->root, '/') .'/';

With this code:

Code: Select all

if(isset($_SESSION['user'])) $this->root = trim($this->root, '/') .'/'. $_SESSION['user'] .'/';

- In the $root property (line 6) you must have the path to the directory where the folders for each user are created.

byronclunz
This solution works great!
It is so unusual to get this level of help for a free code example. Thank You!

chill
Hi Admin, Thank you for this solution. I've gotten the imgbrowse and imgupload to work as described above, but when I try to use more than one session field, it does not work. I have tried

Code: Select all

$_SESSION['first']$_SESSION['last']$_SESSION['id']
and

Code: Select all

$_SESSION['first']'.'$_SESSION['last']'.'$_SESSION['id']
I'm trying to create sub-directories based upon their "firstnamelastnameidnumber". Any help would surely be appreciated.

Admin
Hello,
Try this code:

Code: Select all

$_SESSION['first'].$_SESSION['last'].$_SESSION['id']

Or this:

Code: Select all

$_SESSION['first'].''.$_SESSION['last'].''.$_SESSION['id']

Adv. Posts: 01

Similar Topics