
Subida de imágenes (ayuda)
Publicado por Max (4 intervenciones) el 02/07/2015 05:18:51
Hola amigos, me podrían por favor ayudar a añadir el código que me falta para que permita subir solo imágenes jpg, gif y png.
El archivo lo tengo como gestor.php que se abre una vez pulsado el boton agregar imágenes en el formulario de registro.
Aquí va el código, funciona super bién pero me sube cualquier cosa además de imágenes y lo que necesito es que si el usuario sube cualquier otra cosa me indique: Sólo se permiten jpg, gif o png.
Desde ya Muchas Gracias
El archivo lo tengo como gestor.php que se abre una vez pulsado el boton agregar imágenes en el formulario de registro.
Aquí va el código, funciona super bién pero me sube cualquier cosa además de imágenes y lo que necesito es que si el usuario sube cualquier otra cosa me indique: Sólo se permiten jpg, gif o png.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Subir imágen 1</title>
<link href="estilo1.css" rel="stylesheet" type="text/css" />
<link href="estilo2.css" rel="stylesheet" type="text/css" />
</head>
</html>
<body>
<?php
$fn = "fotografia";
$nf = date("hisjmY");
$ta = ".jpg";
?>
<?php if ((isset($_POST["enviado"])) && ($_POST["enviado"] == "form1")) {
$nombre_archivo = $fn.$nf.$ta;
move_uploaded_file($_FILES['imagen1']['tmp_name'], "imagenes/".$nombre_archivo);
$file = 'imagenes/'.$nombre_archivo;
function image_gd($file)
{
$extension = explode(".",$file);
$ext = count($extension)-1;
if($extension[$ext] == "jpg" || $extension[$ext] == "jpeg")
{
$image = ImageCreateFromJPEG($file);
}
else if($extension[$ext] == "gif"){
$image = ImageCreateFromGIF($file);
}
else if($extension[$ext] == "png"){
$image = ImageCreateFromPNG($file);
}
else
{
echo "Error, extencion no permitida";
die();
}
$thumb_name = substr($file,0,-4);//nombre del thumbnail
$width = imagesx($image);//ancho
$height = imagesy($image);//alto
$nueva_anchura = 453;
$nueva_altura = ($nueva_anchura * $height) / $width ;
if (function_exists("imagecreatetruecolor"))
{
$thumb = ImageCreateTrueColor($nueva_anchura, $nueva_altura);
}
if (!$thumb) $thumb = ImageCreate($nueva_anchura, $nueva_altura);
ImageCopyResized($thumb, $image, 0, 0, 0, 0, $nueva_anchura, $nueva_altura, $width, $height);
//header("Content-type: image/jpeg");
ImageJPEG($thumb, "".$thumb_name.".jpg", 99);
imagedestroy($image);
return $image;
}
/* Forma de uso */
//for($total=$total;$total>0;$total--){
image_gd($file);
//}
?>
<script>
opener.document.form1.imagen1.value="<?php echo $nombre_archivo; ?>";
self.close();
</script>
<?php
}
else
{?>
<form action="gestor.php" method="post" enctype="multipart/form-data" id="form1">
<p>
<input name="imagen1" type="file" class="bot1" />
</p>
<p>
<input name="button" type="submit" class="bot1" id="button" value="Subir Imagen" />
</p>
<input type="hidden" name="enviado" value="form1" />
</form>
<?php }?>
</body>
</html>
Desde ya Muchas Gracias

Valora esta pregunta


0