filename -how to replace special chars?

A place for users and developers of the Xataface to discuss and receive support.

filename -how to replace special chars?

Postby 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
Martin Pruss
 
Posts: 61
Joined: Tue Oct 23, 2007 2:22 pm
Location: Berlin

Re: filename -how to replace special chars?

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: filename -how to replace special chars?

Postby Martin Pruss » Wed Mar 17, 2010 9:12 am

Thanks Steve
have a nice day
Martin Pruss
 
Posts: 61
Joined: Tue Oct 23, 2007 2:22 pm
Location: Berlin


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved