Page 1 of 1

filename -how to replace special chars?

PostPosted: Mon Mar 15, 2010 4:45 am
by Martin Pruss
Hi Steve
Topic Fileupload
I was wondering if it is possible to automaticallly change the filename , to prevent uploading files with special german characters like "ä,ö,ü,ß or even empty space"
Example:"Meier,Ölke pedo.jpg-1.jpg" should become: "meieroelkepedojpg-1.jpg". I noticed that in xataface filenames are changed automatically to prevent overwriting (filename+Int++). Can i safely extend this funktion? Where can i find it?

for the image_filename field its quite easy (excuse my sloppy coding style)
Code: Select all
function beforeInsert(&$record){
$vokale = array(" ", ",", "ö", "ä", "ü", "Ö", "Ä", "Ü", "ß", "/");
     $before = $record->val('image_filename');
   $uniq =  rand(1,100000);

//$h = haystack, $n = needle
function strstrb($h,$n){
    return array_shift(explode($n,$h,2));
}

$after1 = strstrb($before,'.');
$after = str_replace($vokale, "", $after1);

    $record->setValue('extra', $after."".$uniq.".flv");
//$record->setValue('image_filename', str_replace($vokale, "", $before));

}

but how about the file itself?

cheers
Martin

Re: filename -how to replace special chars?

PostPosted: Tue Mar 16, 2010 12:15 pm
by shannah
Hi Martin,

This renaming is done in the /Dataface/FormTool/file.php file.
Alternatively you could put your own renaming/moving code in the beforeSave or afterSave triggers.

-Steve

Re: filename -how to replace special chars?

PostPosted: Wed Mar 17, 2010 9:12 am
by Martin Pruss
Thanks Steve
have a nice day