How to force each user's image upload to their own directory on the server.
I have worked on this for days with no clear postings telling how to get a variable path. Here's my code.
Up at the top of the php module you want:
// INCLUDE THE FCKEDITOR PHP CLASS
include( 'FCKeditor/fckeditor.php' );
Then further down, after the Form statement and exactly where you want the Text Editor in your HTML page:
$folder="$username";
// INSTANTIATE THE CLASS
$fck_editor = new FCKeditor(Html);
// SET UP THE EDITOR VARIABLES
$fck_editor->BasePath = 'FCKeditor/';
$fck_editor->ToolbarSet = 'HTML';
$fck_editor->Width = '435';
$fck_editor->Height = '400';
$fck_editor->Value = $html;
$fck_editor->Config['ImageBrowserURL'] = $fck_editor->BasePath . "../../filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=/$folder/fckImages/";
// CREATE THE EDITOR
$fck_editor->Create() ;
I don't think you have to touch fckconfig.js in the FCKeditor folder, but I did. I made sure all the " FCKConfig.ImageBrowserURL"s were commented out, but I am sure the one in the program overrides them.
Anyway, good luck. FCKeditor is excellent! I just wish there was better documentation or more HowTo's out there. I wasted tons of time that could have been avoided with a good explanation.
Anyway, I hope this one is and good luck!
Additional Comments:
1) The ../../ above is not documented anywhere and is wrong out of the box. I had to add it because the path was incorrect.
2) Apparently it is impossible to use a textarea anymore though it does not say that anywhere. I wasted 2-3 days trying to do that the way we did it before.
3) I finally succeeded with 2.0FC, but that may not have had anything to do with my success.
4) Very hard to debug. Any error and it goes back to the default positon with no clues or it says you have a permission error which I think is an erroneous or at least, confusing error. It is always a generated path problem with few clues.
5) I finally settled on the all PHP solution but with someone smarter with JavaScript, you might not have to. I think it is required to get the $folder evaluated before going to the WS.
I have worked on this for days with no clear postings telling how to get a variable path. Here's my code.
Up at the top of the php module you want:
// INCLUDE THE FCKEDITOR PHP CLASS
include( 'FCKeditor/fckeditor.php' );
Then further down, after the Form statement and exactly where you want the Text Editor in your HTML page:
$folder="$username";
// INSTANTIATE THE CLASS
$fck_editor = new FCKeditor(Html);
// SET UP THE EDITOR VARIABLES
$fck_editor->BasePath = 'FCKeditor/';
$fck_editor->ToolbarSet = 'HTML';
$fck_editor->Width = '435';
$fck_editor->Height = '400';
$fck_editor->Value = $html;
$fck_editor->Config['ImageBrowserURL'] = $fck_editor->BasePath . "../../filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php&ServerPath=/$folder/fckImages/";
// CREATE THE EDITOR
$fck_editor->Create() ;
I don't think you have to touch fckconfig.js in the FCKeditor folder, but I did. I made sure all the " FCKConfig.ImageBrowserURL"s were commented out, but I am sure the one in the program overrides them.
Anyway, good luck. FCKeditor is excellent! I just wish there was better documentation or more HowTo's out there. I wasted tons of time that could have been avoided with a good explanation.
Anyway, I hope this one is and good luck!
Additional Comments:
1) The ../../ above is not documented anywhere and is wrong out of the box. I had to add it because the path was incorrect.
2) Apparently it is impossible to use a textarea anymore though it does not say that anywhere. I wasted 2-3 days trying to do that the way we did it before.
3) I finally succeeded with 2.0FC, but that may not have had anything to do with my success.
4) Very hard to debug. Any error and it goes back to the default positon with no clues or it says you have a permission error which I think is an erroneous or at least, confusing error. It is always a generated path problem with few clues.
5) I finally settled on the all PHP solution but with someone smarter with JavaScript, you might not have to. I think it is required to get the $folder evaluated before going to the WS.
RE: PHP Image Upload with dynamic UserFiles p
This is the javascript you need to insert in the HEAD of your HTML document:
<script type="text/javascript" src="fkeditor/fckeditor.js"></script>
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'content' ) ;
oFCKeditor.BasePath = "fkeditor/" ;
oFCKeditor.Height = "500"; // NOTE: do not put px, just leave the numbers as is
//NOTE: it is important to have the ../../ in the file path
// Also we pass the Type and the ServPath variable
oFCKeditor.Config['ImageBrowserURL'] = oFCKeditor.BasePath + \'../../filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&Type=File&ServerPath=/var/www/user_files/';
oFCKeditor.Config['LinkBrowserURL'] = oFCKeditor.BasePath + \'../../filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&Type=File&ServerPath=/var/www/user_files/';
// This line must come in last once all the configs have been made.
oFCKeditor.ReplaceTextarea() ;
}
</script>
Obviously I have set the Type to 'File' in the query string. If you leave out the Type variable you will get all the different types... Image, Media, File etc...
I will write more in the wiki I I get the time.
RE: PHP Image Upload with dynamic UserFiles p
Since this snippet is embeded in PHP I had to escape the single quotes (i.e. \' ) so make sure you remove all back slashes \ if you just use it HTML.
Also if you embed this snippet in PHP you can dynamically change the directory where the files should be uploaded to.
Instead of haveing /var/www/user_files/ hard wired you can replace it with a variable $path_user_files.
NOTE: Don't forget to give writting properties to the given folder. (i.e. chmod 0777)
RE: PHP Image Upload with dynamic UserFiles p
Thare are 3 more things you need to do
1) in .../connectors/php/config.php You have to set $Config['Enabled'] to TRUE
2) Comment the $Config[UserFilesPath']
3) If you want to use absolute paths in the javascript snippet you have to change .../connectors/php/connector.php
and replace:
$GLOBALS["UserFilesDirectory"] = GetRootPath() . $GLOBALS["UserFilesPath"] ;
with:
$GLOBALS["UserFilesDirectory"] = $GLOBALS["UserFilesPath"] ;
That's it.
RE: PHP Image Upload with dynamic UserFiles p
I have updated the wiki here: http://fckeditor.wikiwikiweb.de/Develop ... le_Browser
RE: PHP Image Upload with dynamic UserFiles p
but i have a problem with the path. when i select an image to preview, the image source is absolute not relative.
any suggestions?
RE: PHP Image Upload with dynamic UserFiles p
thanks a million, saved my life - at least a couple of hours
and to complete the set, use this for links:
$fck_editor->Config['LinkBrowserURL'] = $fck_editor->BasePath . "../../filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&ServerPath=/$folder/fckImages/";
what ist nearly the same, but without "Type=Image" in the querystring.
RE: PHP Image Upload with dynamic UserFiles path
I have all permission! 777
RE: PHP Image Upload with dynamic UserFiles path
With your suggestions now the Imagebrowser and Linkbrowser work... but not the upload....
It tell me "upload complete", but nothing upload!!
I must insert a line link this?
$fck_editor->Config['UserFilesPath'] = $fck_editor->BasePath . "../../filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&ServerPath=/$folder/fckImages/";
????????????????????
THANKS!
Lorenzo
RE: PHP Image Upload with dynamic UserFiles path
RE: PHP Image Upload with dynamic UserFiles path
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | php
These lines fckconfig.js and when i am trying to upload image it is saying Invalid File how to overcome this error and how to configure to add a jpeg image to my fckeditor in fckeditor 4.1 version.
Thanks in advance
RE: PHP Image Upload with dynamic UserFiles p
The good news is I came up with another solutions that was VERY easy to implement and works great. Before you instanciate the class make sure you have a session var created that is specific to this user. I used $_SESSION['user_idNum']. in editor/filemanager/browser/default/connectors/php/config.php change the $Config['UserFilesPath'] to something unique to this user. I used:
$Config['UserFilesPath'] = '/UserFiles/user_' . $_SESSION['user_idNum'] . '/';
This appears to work great for me.
As I am a newbie at this, this is certainly my first time using this editor and it seemed so easy if there is a reason why this is a bad idea please let me know.
Thanks,
Bass Daddy
RE: PHP Image Upload with dynamic UserFiles p
In previous 2.2 versions it would save my files in 'UserFiles/Images' folder. Now they are getting saved and no matter what I have tried to "UserFiles/images'.
so it basically creates folders name images,files, flash, and media with the first letter a small caps.
How can I tell it to access the folders with the first letter capital?
FCKeditor File upload: making UserFilesPath dynamic & secure
Full Subject: FCK editor 2.x: File/image/video upload in different folders for different applications using a single FCKeditor, by making $Config['UserFilesPath'] fully dynamic in a secure way
It can be done in many ways. I am explaining a process, which I applied as per my php applications' code structure. The same code structure/framework I followed for different applications, with each application as a sub-folder in my server. So, there is a logical need to use one single FCKeditor and configure it in some way, so that it work properly for all the applications. The content part of FCKeditor is ok. It can easily be reused by different applications or projects from a single FCKeditor component. But the problem arises with file upload, like image, video or any other document. To make it applicable for different project, the files must be uploaded in separe folders for different projects. And for that $Config['UserFilesPath'] must by configured with dynamic folder path, means different folder path for each project, but calling the the same FCKeditor component in the same location. I am explaning some differnt process together in a step-by-step way. Those worked for me fine with FCKeditor version 2.5.1 and VersionBuild 17566 and I hope they will work for others as well. If it does not work for other developrs, then may be they need to make some tweaks in those process as per their project code structure and folder write permission as well as per the FCKeditor version.
1) In fckeditor\editor\filemanager\connectors\phpconfig.php file
a) Go after global $Config ; and $Config['Enabled'] = false ;
i) There, if want a session dependent secure method: only for single site setting: i.e. one FCKeditor for each one project domain or subdomain, not one FCKeditor for multiple project then place this code:
if(!isset($_SESSION)){
session_start();
}
if(isset($_SESSION['SESSION_SERVER_RELATIVEPATH']) && $_SESSION['SESSION_SERVER_RELATIVEPATH']!="") {
$relative_path=$_SESSION['SESSION_SERVER_RELATIVEPATH'];
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}
N.B.: Here, $_SESSION['SESSION_SERVER_RELATIVEPATH']: relative folder path of the project corresponding to the webroot; should be like "/project/folder/path/" and set this session variable in a common file in your project where the session started. And there should be a configurations/configuration.php as the configuration file in your project. If it's name or path is different you have to place the corresponding path here instead of configurations/configuration.php
ii) If want to use a single FCKeditor component for different projects represented as different sub-folders and with a session dependent secure way (Assuming different session_name for different projects, to differentiate their sessions in a single server). But it will not work if projects represented as sub-domains or different domains, then have to use the session independent way (iii) provided bellow (though it is insecure). Place this code:
if(!isset($_SESSION)){
session_name($_REQUEST['param_project_to_fck']);
session_start();
}
if(isset($_SESSION['SESSION_SERVER_RELATIVEPATH']) && $_SESSION['SESSION_SERVER_RELATIVEPATH']!="") {
$relative_path=$_SESSION['SESSION_SERVER_RELATIVEPATH'];
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}
Please read N.B. at the end of previous point, i.e. point (i)
iii) If want to use a single FCKeditor component for different projects represented either different sub-folders as well as sub-domains or domains (though it is not fully secure). Place this code:
if(isset($_REQUEST['param_project_to_fck']) && $_REQUEST['param_project_to_fck']!=""){ //base64 encoded relative folder path of the project corresponding to the webroot; should be like "/project/folder/path/" before encoding
$relative_path=base64_decode($_REQUEST['param_project_to_fck']);
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}
Please read N.B. at the end of point (i)
b)Now after that for any case you selected, please find this code:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = '/userfiles/' ;
and replace the following code:
if(isset($SERVER_RELATIVEPATH) && $SERVER_RELATIVEPATH==$relative_path) { //to make it relatively secure so that hackers can not create any upload folder automatcally in the server, using a direct link and can not upload files there
$Config['Enabled'] = true ;
$file_upload_relative_path=$SERVER_RELATIVEPATH;
}else{
$Config['Enabled'] = false ;
exit();
}
// Path to user files relative to the document root.
//$Config['UserFilesPath'] = '/userfiles/' ;
//$Config['UserFilesPath'] = $file_upload_relative_path.'userfiles/' ;
$Config['UserFilesPath'] = '/userfiles'.$file_upload_relative_path;
Here $SERVER_RELATIVEPATH is the relative path and it must be set in your project's configuration file included previously.
Here you can set the $Config['UserFilesPath'] with any other dynamic folder path using $file_upload_relative_path variable.In my bluehost linux server, as their was a folder user permission conflict between the project root folder (0755 permission) and the userfiles folder under it and subfolders under userfiles (should be 0777 as per FCKeditor coding), so it does not allow uploading files in those folders. So, I created a folder userfiles at the server webroot (beyond the project root folder), and set the permission to 0777 to it, use the code for the $config setting as :
$Config['UserFilesPath'] = '/userfiles'.$file_upload_relative_path;
But, if you have no problem with write permission in the project's subfolders in your case, then you can use the previous line (commented out in the previous code segment):
$Config['UserFilesPath'] = $file_upload_relative_path.'userfiles/' ;
Mind it, you mast comment out the existing $Config['UserFilesPath'] = '/userfiles/' ; in this file by either replacing or simply commenting out if it exist in other place of the file.
2) If you choose 1) (a) (ii) or (iii) method then open
(a) fckeditor\editor\filemanager\browser\default\browser.html file.
Search for this line: var sConnUrl = GetUrlParam( 'Connector' ) ;
Put these commands after that line:
var param_project_to_fck = GetUrlParam( 'param_project_to_fck' ) ;
Now, Search for this line: sUrl += '&CurrentFolder=' + encodeURIComponent( this.CurrentFolder ) ;
Put this command after that line:
sUrl += '¶m_project_to_fck=' + param_project_to_fck ;
(b) Now, open ckeditor\editor\filemanager\browser\default\frmupload.html file.
Search for this line (it should be in the SetCurrentFolder() function): sUrl += '&CurrentFolder=' + encodeURIComponent( folderPath ) ;
Put this command after that line:
sUrl += '¶m_project_to_fck='+window.parent.param_project_to_fck;
3) Now where you want to show the FCKeditor in your project, you have to put those lines first in the corresponding php file/page:
include_once(Absolute/Folder/path/for/FCKeditor/."fckeditor/fckeditor.php") ;
$oFCKeditor = new FCKeditor(Field_name_for_editor_content_area) ;
$oFCKeditor->BasePath = http_full_path_for_FCKeditor_location.'fckeditor/' ;
$oFCKeditor->Height = 400;
$oFCKeditor->Width = 600;
$oFCKeditor->Value =Your_desired_content_to_show_in_editor;
$oFCKeditor->Create() ;
a) Now, if you choose 1) (a) (ii) or (iii) method then place the following code segment before that line: $oFCKeditor->Create() ;
$oFCKeditor->Config["LinkBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Connector=../../connectors/php/connector.php¶m_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);
$oFCKeditor->Config["ImageBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Type=Image&Connector=../../connectors/php/connector.php¶m_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);
$oFCKeditor->Config["FlashBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Type=Flash&Connector=../../connectors/php/connector.php¶m_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);
b) if you chose 1) (a) (ii) method, then in the above code code segment, just replace all the texts: base64_encode($SERVER_RELATIVEPATH) with this one: base64_encode(session_name())
And you are done.
Thanks for share the
Thanks for share the informational post :)
Here is the code I have changed in my config.php file
very nice and helpful
very nice and helpful information