Last active
August 29, 2015 14:20
-
-
Save mrroot5/f91fcbe132582a51697c to your computer and use it in GitHub Desktop.
Snippets subida ficheros. Obtener extensión fichero y cambiar nombre fichero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_file_extension($file_name = '') { | |
$file_name = (empty($file_name)) ? 'bla.bla..pdf' : $file_name; | |
preg_match('/[^\.]+$/i', $file_name, $ext); | |
return $ext[0]; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
var_dump(merge_file_extension()); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function merge_file_extension($file_name = '', $extension = '', $addon_type = '') { | |
$file_name = (empty($file_name)) ? 'bla.bla..pdf' : $file_name; | |
$extension = (empty($extension)) ? get_file_extension($filename) : $extension; | |
switch(trim($addon_type)) { | |
case 'datetime': | |
$filename_addon = date('YmdHis'); | |
break; | |
case 'microtime': | |
$filename_addon = microtime(); | |
break; | |
default: | |
$filename_addon = time(); | |
break; | |
} | |
$file_name = substr(strtolower($file_name), 0, -(strlen($ext)+1)).'-'.$filename_addon.'.'.$ext; | |
return $file_name; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment