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
-
- Posts:6
CKEditor Folder by User in imgupload and imgbrowse
Admin
Posts:805
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:
With this code:
To create a new directory, you can use this code in php:
Code: Select all
mkdir('/path/to/my_dir', 0755);
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();
Code: Select all
$upload_dir = trim($upload_dir, '/') .'/';
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
Posts:6
Great! That works. Almost there... now how can I modify imgbrowse so that it looks (only) in the same directory?
Admin
Posts:805
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:
With this code:
- In the $root property (line 6) you must have the path to the directory where the folders for each user are created.
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, '/') .'/';
Code: Select all
if(isset($_SESSION['user'])) $this->root = trim($this->root, '/') .'/'. $_SESSION['user'] .'/';
byronclunz
Posts:6
This solution works great!
It is so unusual to get this level of help for a free code example. Thank You!
It is so unusual to get this level of help for a free code example. Thank You!
chill
Posts:7
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 and I'm trying to create sub-directories based upon their "firstnamelastnameidnumber". Any help would surely be appreciated.
Code: Select all
$_SESSION['first']$_SESSION['last']$_SESSION['id']
Code: Select all
$_SESSION['first']'.'$_SESSION['last']'.'$_SESSION['id']
Admin
Posts:805
Hello,
Try this code:
Or this:
Try this code:
Code: Select all
$_SESSION['first'].$_SESSION['last'].$_SESSION['id']
Code: Select all
$_SESSION['first'].''.$_SESSION['last'].''.$_SESSION['id']