AjaxUpload - Rename files

Hi,

we use the extra AjaxUpload in our webproject. Sometimes customers use very “funny” filenames.
Is there a solution to rename the files before they are storaged and send by FormIt?

Or did someone know what other solution for that problem can be good?

You could try to add a custom hook-snippet that runs before the AjaxUpload2Formit and AjaxUploadAttachments hooks and overwrites the “originalName” value of the files that are stored in the session.

<?php
$uid = $modx->getOption('ajaxuploadUid', $scriptProperties, '');
foreach ($_SESSION['ajaxupload'][$uid] as $fileId => &$fileInfo) {
    $fileInfo['originalName'] = '...'; //generate some random name for the file here or maybe use $fileId
}
return true;

Maybe filesluggy works with it? That’ll normalise filenames on upload, though extras do need to monitor for the file name change to avoid broken URLs/references.

Thanks, that can be a starting point.

That sounds interesting, thanks.