Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Image Uploaded With CKFinder

Can I rename an image that is uploaded using CKFinder?

like image 647
Francisc Avatar asked Aug 31 '10 15:08

Francisc


1 Answers

Do you use the PHP version of CKFinder? If so, the following might help.

When uploading files, you can automatically remove spaces, characters with accents, and such. Set "ForceAscii" to "true" in the config.php file:

$config['ForceAscii'] = true;

The code for the "ForceAscii" setting is found starting on line 59 in this file:
ckfinder\core\connector\php\php5\CommandHandler\FileUpload.php

    if ($_config->forceAscii()) {
      $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName);
    }

To rename the file as it's uploaded, you could add your own code to the "ForceAscii" code.

To add some Static text to the beginning or the end:

    if ($_config->forceAscii()) {
        $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName);
        $sFileName .= "YourTextHere"; // Append your text
        $sFileName = "YourTextHere" . $sFileName; // Prepend your text
    }

Just before the force ascii code is a string replace, you could add your own version of a string replace if that would meet your goals.

$sFileName = str_replace(array(":", "*", "?", "|", "/"), "_", $sUnsafeFileName);

If the text used for the rename will vary, you'll need to provide a lot more details:
Will the text vary depending on which user is uploading the file?
Will it vary for each image, regardless of who uploads it?
What will determine the actual text that is used (based on username?).

The latest version, 2.1 allows the user to upload multiple files at one time. This could affect the approach you take.

If you provide additional information, I'll see if I can come up with a better answer.


Is this meant to allow the end user to rename their images? It is possible for the user to rename an image as follows:

When they are looking at the images in the file browser window, they would right click on an image. "Rename" is one of the options in the context menu.

EDIT: The latest version of CKFinder (2.1) has a config setting that is placed in the config.js file:

config.showContextMenuArrow = true;

this setting allows the user to access the context menu by clicking on an arrow that appears in the corner of the image.

Be Well,
Joe

like image 105
codewaggle Avatar answered Oct 06 '22 03:10

codewaggle