Ver Mensaje Individual
  #10 (permalink)  
Antiguo 17/02/2010, 09:22
Avatar de SalomonHe
SalomonHe
 
Fecha de Ingreso: febrero-2010
Mensajes: 28
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Imagenes con PHP

Código HTML:
Ver original
  1. <?php
  2.  
  3. include 'conexion.php';
  4. $vartexto = $_POST["campotexto"];
  5. $c1       = $_POST["casilla1"];
  6. $c2       = $_POST["casilla2"];
  7. $c3       = $_POST["casilla3"];
  8. $c4       = $_POST["casilla4"];
  9. $id       = $_POST["oculto"];
  10.  
  11. $imagen =$_FILES['imagen1']['name'];
  12.  
  13. // Actualiza la imagen
  14. if ( $imagen != "" )
  15.  {
  16.    $extensiones=array("html","exe","php","txt");
  17.    $path="./upload";
  18.    $nombre = $_FILES['imagen1']['name'];
  19.    $tamanio= $_FILES['imagen1']['size'];
  20.    $tipo   = $_FILES['imagen1']['type'];
  21.    $var    =explode(".","$nombre");
  22.    $num = count($extensiones);
  23.    $valor = $num-1;
  24.    for($i=0; $i<=$valor; $i++) {
  25.        if($extensiones[$i] == $var[1]) {
  26.          echo "Tipo de Archivo no admitido";
  27.              exit;
  28.        }
  29.      }
  30.         // Borra la imagen anterior
  31.        $delimagen  = mysql_query("select * from abogados_mybd.prueba WHERE id = $id ", $conexion);
  32.        if ($row= mysql_fetch_array($delimagen))
  33.       {
  34.       $archivo   = $row["imagen"];
  35.       @unlink($archivo);
  36.       }
  37.    
  38.       move_uploaded_file( $_FILES['imagen1']['tmp_name'], "$path/$nombre" );
  39.       @unlink($_FILES['imagen1']['tmp_name']);
  40.        $sql1 = "UPDATE abogados_mybd.prueba SET imagen = '$path/$nombre'  WHERE id = $id ";
  41.        $result1    = mysql_query($sql1);  
  42.  }
  43.   else   
  44.  {
  45.  $path   = "";
  46.  $nombre = "";
  47.  }