Quantcast
Channel: ASPRunner forums
Viewing all articles
Browse latest Browse all 2586

Change file name and save file size in field

$
0
0
Hello. I have a file field to save pdf files. In Before Add event I want to change original name of file by friendly name deleting ñ, á, é,....
I want also to save size of file in bytes into another field calles file_size.
¿Any idea? Thanks

For example, I can use this function to save as a slug title of news:
$separador = '-';//ejemplo utilizado con guión medio
$originales = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýý';
$modificadas = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyy';

//Quitamos todos los posibles acentos
$url = strtr(utf8_decode($values['title']), utf8_decode($originales), $modificadas);

//Convertimos la cadena a minusculas
$url = utf8_encode(strtolower($url));

//Quitamos los saltos de linea y cuanquier caracter especial
$buscar = array(' ', '&', '\r\n', '\n', '+', '"', '"');
$url = str_replace ($buscar, $separador, $url);
$buscar = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$reemplazar = array('', $separador, '');
$url = preg_replace ($buscar, $reemplazar, $url);

$values['slug']=$url;

return true;

Viewing all articles
Browse latest Browse all 2586

Trending Articles