In this topic you will learn how to modify the generated KTML code to create dynamic folders. In the final form, all files - images, documents and templates will be uploaded into the <site_root>\uploads\[user_name] folder.
To achieve this you have to modify the page that contains the KTML control - the article posting page - and modify the lines that set the upload folders. Initially, the value is static, a string - "uploads/" to which you have to append code that retrieves and outputs the session variable value.
On PHP, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:
The media and documents upload folder:
$ktml_content_art->setModuleProperty("file", "UploadFolder", "uploads/", false);
$ktml_content_art->setModuleProperty("media", "UploadFolder", "uploads/", false);
The media and documents upload folder URL - this is the URL used to reference files through links
$ktml_content_art->setModuleProperty("file", "UploadFolderUrl", "uploads/", true);
$ktml_content_art->setModuleProperty("media", "UploadFolderUrl", "uploads/", true);
The templates uploading folder.
$ktml_content_art->setModuleProperty("templates", "UploadFolder", "uploads/", false);
On PHP you can use the InterAKT Mark-up language to reference variable names. You can find out more details on the InterAKT Mark-up Language syntax and possible values in the MX Kollection documentation, here.
Import for this tutorial is the syntax to use in order to get the kt_login_user session's variable value you have to write: {SESSION.kt_login_user}. To make the upload folders dynamic, simply append this code after the uploads/ static text. The three lines of code will become:
The media and documents upload folder:
$ktml_content_art->setModuleProperty("file", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
$ktml_content_art->setModuleProperty("media", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
The media and documents upload folder URL - this is the URL used to reference files through links
$ktml_content_art->setModuleProperty("file", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true);
$ktml_content_art->setModuleProperty("media", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true);
The templates uploading folder.
$ktml_content_art->setModuleProperty("templates", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
Now, when you login and upload an image to the server, it will be stored inside the user's personal folder.
On ASP, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:
The media and documents upload folder:
ktml_content_art.setModuleProperty "file", "UploadFolder", "uploads/", false
ktml_content_art.setModuleProperty "media", "UploadFolder", "uploads/", false
The media and documents upload folder URL - this is the URL used to reference files through links
ktml_content_art.setModuleProperty "file", "UploadFolderUrl", "uploads/", true
ktml_content_art.setModuleProperty "media", "UploadFolderUrl", "uploads/", true
The templates uploading folder.
ktml_content_art.setModuleProperty "templates", "UploadFolder", "uploads/", false
On ASP you can use the InterAKT Mark-up language to reference variable names. You can find out more details on the InterAKT Mark-up Language syntax and possible values here. Import for this tutorial is the syntax to use in order to get the kt_login_user session's variable value you have to write: {SESSION.kt_login_user}. To make the upload folders dynamic, simply append this code after the uploads/ static text. The three lines of code will become:
The media and documents upload folder:
ktml_content_art.setModuleProperty "file", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false;
ktml_content_art.setModuleProperty "media", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false;
The media and documents upload folder URL - this is the URL used to reference files through links
ktml_content_art.setModuleProperty "file", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true
ktml_content_art.setModuleProperty "media", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true
The templates uploading folder.
ktml_content_art.setModuleProperty "templates", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false
Now, when you login and upload an image to the server, it will be stored inside the user's personal folder.
On ColdFusion, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:
The media and documents upload folder:
ktml_content_art.setModuleProperty "file", "UploadFolder", "uploads/", false
ktml_content_art.setModuleProperty "media", "UploadFolder", "uploads/", false
The media and documents upload folder URL - this is the URL used to reference files through links
ktml_content_art.setModuleProperty "file", "UploadFolderUrl", "uploads/", true
ktml_content_art.setModuleProperty "media", "UploadFolderUrl", "uploads/", true
The templates uploading folder.
ktml_content_art.setModuleProperty "templates", "UploadFolder", "uploads/", false
On ColdFusion you can use the InterAKT Mark-up language to reference variable names. You can find out more details on the InterAKT Mark-up Language syntax and possible values here. Import for this tutorial is the syntax to use in order to get the kt_login_user session's variable value you have to write: {SESSION.kt_login_user}. To make the upload folders dynamic, simply append this code after the uploads/ static text. The three lines of code will become:
The media and documents upload folder:
ktml_content_art.setModuleProperty("file", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
ktml_content_art.setModuleProperty("media", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
The media and documents upload folder URL - this is the URL used to reference files through links
ktml_content_art.setModuleProperty("file", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true);
ktml_content_art.setModuleProperty("media", "UploadFolderUrl", "uploads/{SESSION.kt_login_user}/", true);
The templates uploading folder.
ktml_content_art.setModuleProperty("templates", "UploadFolder", "uploads/{SESSION.kt_login_user}/", false);
Now, when you login and upload an image to the server, it will be stored inside the user's personal folder.
The way to go to make the uploads folder dynamic is identical for both ASP.NET 1.1 and ASP.NET 2.0. After creating the page that contains the KTML control with a static upload folder, upload folder URL and templates upload folder paths, you will have to add several lines that create a new path, dynamic this time:
Open the page containing the KTML control you want to change, with a text editor or in your development environment.
Locate the Page_Load section of the page, or create a new one.
Add the following lines to the page - the username is assumed to be stored in the kt_login_user session variable, and the KTML instance is named KTML4_1:
First define the new media and document upload folder. It's path will be the uploads folder in the site root, and then the username:
KTML4_1.UploadFolder = "~/uploads/" + Session["kt_login_user"] + "/";
Next set the Upload folder URL value, and the templates folder to the same paths:
KTML4_1.UploadFolderUrl = "~/uploads/" + Session["kt_login_user"] + "/";
KTML4_1.TemplatesFolder = "~/uploads/" + Session["kt_login_user"] + "/";
Save the page. Now when a logged in user will upload files, they will be saved in the particular folders.
On JSP the approach is similar to the one presented for the server models above: in the page that contains the KTML editor locate the lines that define the static upload file, URL and template upload paths, Then modify them - replace the static value with a concatenation of the basic path - uploads/ - with the username saved in the session variable:
The lines of code that interest us are placed within the JSP code that sets the KTML module properties, and are as follows:
<ktml:moduleProperty module="file" name="UploadFolder" value="uploads/" exportToJs="true" />
<ktml:moduleProperty module="file" name="UploadFolderUrl" value="uploads/" exportToJs="true" />
<ktml:moduleProperty module="media" name="UploadFolder" value="uploads/" exportToJs="true" />
<ktml:moduleProperty module="media" name="UploadFolderUrl" value="uploads/" exportToJs="true" />
<ktml:moduleProperty module="templates" name="UploadFolder" value="uploads/" exportToJs="true" />
The new code will have a different section for the value attribute, as shown below:
<ktml:moduleProperty module="file" name="UploadFolder" value="<%= "uploads/" + pageContext.getAttribute("kt_login_user", PageContext.SESSION_SCOPE) + "/" %> exportToJs="true" />
<ktml:moduleProperty module="file" name="UploadFolderUrl" value="<%= "uploads/" + pageContext.getAttribute("kt_login_user", PageContext.SESSION_SCOPE) + "/" %> exportToJs="true" />
<ktml:moduleProperty module="media" name="UploadFolder" value="<%= "uploads/" + pageContext.getAttribute("kt_login_user", PageContext.SESSION_SCOPE) + "/" %> exportToJs="true" />
<ktml:moduleProperty module="media" name="UploadFolderUrl" value="<%= "uploads/" + pageContext.getAttribute("kt_login_user", PageContext.SESSION_SCOPE) + "/" %> exportToJs="true" />
<ktml:moduleProperty module="templates" name="UploadFolder" value="<%= "uploads/" + pageContext.getAttribute("kt_login_user", PageContext.SESSION_SCOPE) + "/" %> exportToJs="true" />
Save the page. When a logged in user will access the page for the first time, the folder will be created.