function subirArchivo($arch, $folder, $filename, $extensionesPermitidas, $maxFileSize, &$error, &$finalFilename) { $tmpfile = $arch["tmp_name"]; $partes_ruta = pathinfo(strtolower($arch["name"])); if (!in_array($partes_ruta["extension"], $extensionesPermitidas)) { $error = "El archivo debe tener alguna de las siguientes extensiones: ".implode(" o ", $extensionesPermitidas)."."; return false; } $filename = stringToLower($filename.".".$partes_ruta["extension"]); $finalFilename = $folder.$filename; if (!is_uploaded_file($tmpfile)) { $error = "El archivo no subió correctamente."; return false; } if (filesize($tmpfile) > $maxFileSize) { $error = "El archivo no puede ser mayor a ".tamanoArchivo($maxFileSize)."."; return false; } if (!move_uploaded_file($tmpfile, $folder.$filename)) { $error = "El archivo no pudo ser guardado."; return false; } return true; }
return false; // Si el nombre del archivo es igual a la extensión probablemente no tenga extensión, asi que es inválido.. if ($file == $ext) return false; // Solo se pueden descargar algunas de estas extensiones.. if (($ext != ".bmp") and ($ext != ".doc") and ($ext != ".docx") and ($ext != ".jpeg") and ($ext != ".jpg") and ($ext != ".mpeg") and ($ext != ".mpg") and ($ext != ".pdf") and ($ext != ".png") and ($ext != ".ppt") and ($ext != ".xls") and ($ext != ".xlsx")) return false; return true; } // Revierto la pseudoencriptación que le aplico ademas del base64.. $file = substr_replace($_REQUEST["fl"], "", 17, 1); $file = stringToLower(base64_decode(substr_replace($file, strrev(substr($file, 7, 7)), 7, 7))); if ((substr($file, 0, 10) == "\\ntwebart") or (substr($file, 0, 10) == "//ntwebart")) $file = substr_replace($file, "D:", 0, 11); // Es 11 en vez de 10, porque sería //ntwebart3 o //ntwebart1.. $ext = substr($file, strrpos($file, ".")); //******* INICIO VALIDACIÓN EL ARCHIVO QUE SE QUIERE VER/DESCARGAR ******* if (!archivoValido($file, $ext)) $file = $_SERVER["DOCUMENT_ROOT"]."/archivo_invalido.html"; //******* FIN VALIDACIÓN EL ARCHIVO QUE SE QUIERE VER/DESCARGAR ******* $mode = "i"; if (isset($_REQUEST["md"])) $mode = $_REQUEST["md"]; if ($ext == ".pdf") header("Content-type: application/pdf");
function setUrlAmigable($titulo) { return stringToLower(removeAccents(str_replace(array(" ", "º", "°", "ñ", "Ñ"), array("-", "", "", "n", "N"), $titulo))).".html"; }
/** * Replace the string symbols with another symbols. * Remove all symbols except alphanumeric. * Usefull for transliteration cyrillic strings. * @param string $haystack * @param array $keypairs * @param bool $lowercase * @return string */ function stringChange($haystack, array $keypairs, $lowercase = true) { if (empty($keypairs)) { return ''; } $haystack = str_replace(" ", "", $haystack); // Remove all characters except alphanumeric $haystack = preg_replace("/([A-z0-9])+/", '', $haystack); $haystack = strtr($haystack, $keypairs); if ($lowercase) { $haystack = stringToLower($haystack); } return empty($haystack) ? '' : $haystack; }
function validarExtension($archivo, $extensionesValidas = array()) { $ext = stringToLower(substr($archivo, strrpos($archivo, ".") + 1, 20)); return in_array($ext, $extensionesValidas); }
function getWindowsLoginName($upper = false) { if (isset($_SESSION["FAKE_REMOTE_USER"])){ return stringToUpper($_SESSION["FAKE_REMOTE_USER"]); } // Estas dos primeras lineas se agregan para que ande el motor de búsqueda.. if (!isset($_SERVER["REMOTE_USER"])) $_SERVER["REMOTE_USER"] = "******"; $cred = explode("\\", $_SERVER["REMOTE_USER"]); if (count($cred) == 1) array_unshift($cred, "No hay información disponible sobre el dominio donde Ud. está logueado."); list($domain, $user) = $cred; if ($upper) return stringToUpper($user); else return stringToLower($user); }
function validarExtension($archivo, $extensionesValidas = array("bmp", "gif", "jpg", "jpeg", "png")) { $ext = stringToLower(substr($archivo, strrpos($archivo, ".") + 1, 20)); return in_array($ext, $extensionesValidas); }