filename -how to replace special chars?
Archived from the Xataface Users forum.
Martin Pruss — Mon Mar 15, 2010 4:45 am
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
shannah — Tue Mar 16, 2010 12:15 pm
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
Martin Pruss — Wed Mar 17, 2010 9:12 am
Thanks Steve
have a nice day