Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/05/2010, 05:43
portablepsp
 
Fecha de Ingreso: mayo-2008
Mensajes: 76
Antigüedad: 16 años
Puntos: 1
Respuesta: subir imagen al servidor

Este es el formulario:

<form name='frm_img_cabecera' method='post' action='index.php' enctype="multipart/form-data">
<input type='hidden' name='hacer' value='noticia' />
<table>
<tr>
<td colspan='2'>NOTICIA</td>
</tr>
<tr>
<td>Fecha</td>
<td class='newfecha'> <input size="30" id="f_date1" name='fecha'/>&nbsp;&nbsp;<span class='cal' id="f_btn1">CAL</span></td>
</tr>
<tr>
<td>Título</td>
<td><input type='text' name='titulo' size='80' value="<?php echo $fila['titulo'];?>" ></input></td>
</tr>

<tr>
<td>Descripcion</td>
<td class='textarea_editor'><textarea class='texta' name="descripcion"></textarea></td>
</tr>

<tr>
<td>Imagen</td>
<td><input type='file' name='imagen_noticia' size='55'/></td>
</tr>

<tr>
<td>PDF Adjunto</td>
<td><input type='file' name='pdf_noticia' size='55'/></td>
</tr>

<tr>
<td>Fuente</td>
<td><input type='text' name='fuente' size='80' value='<?php echo $fila['fuente'];?>'></input></td>
</tr>

<tr>
<td><input type='submit' value='enviar' /></td>
</tr>
</table>

</form>






y esto inserta una noticia:


function insertar_noticia($con,$titulo,$descripcion,$fecha, $fuente,$imagen_noticia){

$sql="INSERT into noticias (titulo,descripcion,fuente,fecha)
VALUES ('$titulo','$descripcion','$fuente','$fecha')";
//echo $sql;
mysqli_query($con,$sql) or die ("error de insercion");

$sql="SELECT MAX(idnoticias) from noticias";
$resultado=mysqli_query($con,$sql);
$max=mysqli_fetch_row($resultado);

if ( !empty ($_FILES['imagen_noticia']['tmp_name'])){
$info=GetImageSize($_FILES['imagen_noticia']['tmp_name']);

switch ($info[2]){
case 1:
$extension=gif;
break;
case 2:
$extension=jpg;
break;
case 3:
$extension=png;
break;
}

$dir = "../imagenes/actualidad/noticias/";

chmod($dir,0777);
copy($_FILES['imagen_noticia']['tmp_name'],$dir.$max['0'].".".$extension);

$sql="UPDATE noticias SET imagen_noticia = 'imagenes/actualidad/noticias/".$max['0'].".".$extension."'
where idnoticias =".$max['0'];
//echo $sql;
mysqli_query($con,$sql) or die ("<div class='error'>error de actualizacion IMAGEN</div>");
}

if ( !empty ($_FILES['pdf_noticia']['tmp_name'])){
$archivo_temporal = $_FILES['pdf_noticia']['name'];

$extension = extension($archivo_temporal);
if ($extension == 'pdf'){

//echo "ruta: ".$dir = "../imagenes/actualidad/noticias/pdf/";
$dir = "../imagenes/actualidad/noticias/pdf/";
chmod($dir,0777);
copy($_FILES['pdf_noticia']['tmp_name'],$dir.$max['0'].".".$extension);

$sql="UPDATE noticias SET pdf_noticia = 'imagenes/actualidad/noticias/pdf/".$max['0'].".".$extension."'
where idnoticias =".$max['0'];
echo $sql;
mysqli_query($con,$sql) or die ("<div class='error'>error de actualizacion PDF</div>s");
}
else echo "<div class='error'>Solo puedes subir archivos pdf</div>";
}

header ("Location: index.php?hacer=noticias&ruta1=noticias");
}


El tamaño de la imagen no lo se mirare a ver si esta limitado