Last active
December 22, 2015 04:29
-
-
Save fastcodecoq/6417480 to your computer and use it in GitHub Desktop.
Obtener la extensión de un archivo en Php
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_extension ($file_name = "simple._práctico_.inc.txt"){ | |
try{ | |
if(!preg_match("/^([a-zA-Z0-9àèìòùáéíóúäëïöüÀÈÌÒÙÁÉÍÓÚÄËÏÖÜ\s\._-]+)$/i", $file_name)) | |
return false; | |
else{ | |
$file_name = explode(".", $file_name); | |
if(!count($extension) > 1) | |
{ | |
return false; | |
}else{ | |
$extension = (String) strtolower( end( $file_name)); | |
return $extension; | |
} | |
} | |
} catch(Excetpion $e){ | |
return false; | |
} | |
} | |
/* USO | |
get_extension($_FILES["name"]); | |
|| en caso de tratarse de carga múltiple | |
foreach($_FILES["name"] as $file_name) { get_extension($file_name); } (en caso de multiples archivos) | |
*/ | |
//TEST | |
$ext = get_extension(); | |
if($ext) | |
echo $ext; | |
else | |
echo "Parece que no has pasado un nombre de archivo válido"; | |
//happy coding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment