Modify the generated code

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.

 

Add the dynamic value on PHP

On PHP, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:

  1. The media and documents upload folder:

    $ktml_content_art->setModuleProperty("file", "UploadFolder", "uploads/", false);
    $ktml_content_art->setModuleProperty("media", "UploadFolder", "uploads/", false);

     

  2. 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);

     

  3. 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:

  1. 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);

     

  2. 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);

     

  3. 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.

 

Add the dynamic value on ASP_VBScript

On ASP, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:

  1. The media and documents upload folder:

    ktml_content_art.setModuleProperty "file", "UploadFolder", "uploads/", false
    ktml_content_art.setModuleProperty "media", "UploadFolder", "uploads/", false

     

  2. 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

     

  3. 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:

  1. 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;

     

  2. 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

     

  3. 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.

 

Add the dynamic value on ColdFusion

On ColdFusion, there are three places in the code that must be modified in order to use individual folders, all inside the setModuleProperty calls:

  1. The media and documents upload folder:

    ktml_content_art.setModuleProperty "file", "UploadFolder", "uploads/", false
    ktml_content_art.setModuleProperty "media", "UploadFolder", "uploads/", false

     

  2. 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

     

  3. 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:

  1. 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);

     

  2. 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);

     

  3. 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.

 

Add the dynamic value on ASP.NET 1.1. and 2.0

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:

  1. Open the page containing the KTML control you want to change, with a text editor or in your development environment.

  2. Locate the Page_Load section of the page, or create a new one.

  3. 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:

  4. Save the page. Now when a logged in user will upload files, they will be saved in the particular folders.

 

Add the dynamic value on JSP

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:

  1. 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" />
     

  2. 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.