1
0
Fork 0
milfskleper/includes/upload_generico.php

47 lines
2.1 KiB
PHP

<?php
echo 'content="text/plain; charset=utf-8"';
// En versiones de PHP anteriores a la 4.1.0, debería utilizarse $HTTP_POST_FILES en lugar
// de $_FILES.
//$campo= "campo$_REQUEST[campo]-$_REQUEST[item]";
$campo= "$_REQUEST[campo]-$_REQUEST[item]";
$tipo = $_FILES["$campo"]['type'];
//$nombrecillo = $_FILES['myfile']['nombrecillo'];
if($tipo=="image/png") {$ext = ".png"; $imagen=1; }
elseif($tipo=="image/jpeg") {$ext = ".jpg"; $imagen=1; }
elseif($tipo=="image/gif") {$ext = ".gif"; $imagen=1; }
else {
$ext = explode(".", $_FILES["$campo"]['name']);
$ext = ".".strtolower($ext[count($ext) - 1]);
// $ext = "novalida";
$imagen=0;}
$nombrecillo= $_REQUEST['nombrecillo'];
$name = "$nombrecillo";
$dir_subida = '/home/images_secure/';
$fichero_subido = $dir_subida ."full/".$name;
if (move_uploaded_file($_FILES["$campo"]['tmp_name'], $fichero_subido)) {
if($imagen==1) {
echo miniaturizar($name,"150",$dir_subida);
echo miniaturizar($name,"300",$dir_subida);
echo miniaturizar($name,"600",$dir_subida);
}
} else {
echo "¡Posible ataque de subida de ficheros!\n";
}
function miniaturizar($file,$width,$directorio) {
//$archivo = $file;
$archivo = "$directorio"."full/".$file;
$file_info = getimagesize($archivo);
$ratio = $file_info[0] / $file_info[1];
$newwidth = $width;
$newheight = round($newwidth / $ratio);
$ext = explode(".", $file);
$ext = strtolower($ext[count($ext) - 1]);
if ($ext == "jpeg") $ext = "jpg";
switch ($ext) {
case "jpg":
$img = imagecreatefromjpeg($archivo);
// $img = imagecreatefromstring($archivo);
break;
case "png":
$img = imagecreatefrompng($archivo);
break;
case "gif":
$img = imagecreatefromgif($archivo);
break;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagealphablending( $thumb, false );
imagesavealpha( $thumb, true );
imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $file_info[0], $file_info[1]);
if($ext=="jpg") {
imagejpeg($thumb,$directorio.$width."/$file", 80);
}else {
imagepng($thumb,$directorio.$width."/$file", 9);
}
}
?>