Page 1 of 1
CKEditor Folder by User in imgupload and imgbrowse
Posted: 20 Oct 2015, 03:18
by byronclunz
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.
CKEditor Folder by User in imgupload and imgbrowse
Posted: 20 Oct 2015, 09:11
by Admin
Hello,
To create a new directory, you can use this code in php:
- 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):
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);
}
CKEditor Folder by User in imgupload and imgbrowse
Posted: 21 Oct 2015, 15:07
by byronclunz
Great! That works. Almost there... now how can I modify imgbrowse so that it looks (only) in the same directory?
CKEditor Folder by User in imgupload and imgbrowse
Posted: 21 Oct 2015, 17:58
by 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.
CKEditor Folder by User in imgupload and imgbrowse
Posted: 21 Oct 2015, 19:34
by byronclunz
This solution works great!
It is so unusual to get this level of help for a free code example. Thank You!
CKEditor Folder by User in imgupload and imgbrowse
Posted: 21 Feb 2017, 21:53
by 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.
CKEditor Folder by User in imgupload and imgbrowse
Posted: 22 Feb 2017, 06:26
by 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']