Foros del Web » Programando para Internet » PHP »

Ayuda mejorar codigo

Estas en el tema de Ayuda mejorar codigo en el foro de PHP en Foros del Web. Bueno es un codigo q tengo q entregar lo antes posible pero nose q tiene q aveces anda bien y aveces no,, alguien lo puede ...
  #1 (permalink)  
Antiguo 03/06/2006, 10:10
 
Fecha de Ingreso: junio-2006
Mensajes: 15
Antigüedad: 17 años, 9 meses
Puntos: 0
Busqueda Ayuda mejorar codigo

Bueno es un codigo q tengo q entregar lo antes posible pero nose q tiene q aveces anda bien y aveces no,, alguien lo puede revisar y decirme como lo arreglo,, es muy feo como esta echo :S..

Lo q falla es el sistema de subir archivos
Código PHP:
<? include("../seguridad.php"); include("../../system.php");?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"h**p://w*w.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>*** - Subir Lista</title>
<meta h**p-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
    font-size: 18px;
    font-weight: bold;
}
.style2 {font-size: 12px}
-->
</style>
</head>

<body>
<? include ("../inc/admin_top.php")?>

<?php 
$edis 
$_REQUEST['edi'];
if (isset(
$edis)){ 
$art=msq("    SELECT *
            FROM articulos
            WHERE id = $edis
            LIMIT 1
        "
);
$arts=mysql_fetch_array($art);        
?>
<table width="764" border="0" cellpadding="0">
  <tr>
    <td width="760" align="center" class="text12">
<table width="760" border="0" cellpadding="3" cellspacing="0" class="text11">
        <tr bgcolor="#CCCCCC"> 
          
        <td width="100%" class="text11"><strong><font color="#000000">Modificar 
          Articulo </font></strong></td>
        </tr>
      </table>

<table width="464" border="1">
  <tr>
    <td width="454"><form method=post action=in.php?action=edit enctype="multipart/form-data">
          <table align="center">
            <tr> 
              <td>Nombre:</td>
              <td><input name=nombre type=text value="<?php echo $arts[nombre]; ?>" size="50" maxlength="255"></td>
            </tr>
            <tr> 
              <td>Web Review:</td>
              <td><input name=pagrev type=text value="<?php if ($arts[pagrev]) { echo $arts[pagrev]; } else { echo 'h**p://'; } ?>" size="50" maxlength="255"></td>
            </tr>
            <tr> 
              <td>Web Oficial:</td>
              <td><input name=pagofi type=text value="<?php if ($arts[pagofi]) { echo $arts[pagofi]; } else { echo 'h**p://'; } ?>" size="50" maxlength="255"></td>
            </tr>
            <tr> 
              <td>Rubro:</td>
              <td><select name="id_tipo">
                  <option value="0">- Rubro -</option>
                  <option value='1' <?php if ($arts[id_tipo] == 1) {echo selected;} ?>>Procesadores</option>
                  <option value='2' <?php if ($arts[id_tipo] == 2) {echo selected;} ?>>Motherboards</option>
                  <option value='3' <?php if ($arts[id_tipo] == 3) {echo selected;} ?>>Memorias</option>
                  <option value='4' <?php if ($arts[id_tipo] == 4) {echo selected;} ?>>Placas 
                  de Video</option>
                  <option value='5' <?php if ($arts[id_tipo] == 5) {echo selected;} ?>>Fuentes</option>
                  <option value='6' <?php if ($arts[id_tipo] == 6) {echo selected;} ?>>Gabinetes</option>
                  <option value='7' <?php if ($arts[id_tipo] == 7) {echo selected;} ?>>Discos 
                  Rigidos</option>
                  <option value='8' <?php if ($arts[id_tipo] == 8) {echo selected;} ?>>Coolers</option>
                  <option value='9' <?php if ($arts[id_tipo] == 9) {echo selected;} ?>>Equipos 
                  Armados</option>
                  <option value='10' <?php if ($arts[id_tipo] == 10) {echo selected;} ?>>Reproductores 
                  MP3</option>
                  <option value='11' <?php if ($arts[id_tipo] == 11) {echo selected;} ?>>Parlantes 
                  </option>
                  <option value='12' <?php if ($arts[id_tipo] == 12) {echo selected;} ?>>Monitores</option>
                  <option value='13' <?php if ($arts[id_tipo] == 13) {echo selected;} ?>>Mouse 
                  y Teclado</option>
                  <option value='14' <?php if ($arts[id_tipo] == 14) {echo selected;} ?>>Combos</option>
                  <option value='15' <?php if ($arts[id_tipo] == 15) {echo selected;} ?>>Impresoras</option>
                  <option value='16' <?php if ($arts[id_tipo] == 16) {echo selected;} ?>>Opticos</option>
                  <option value='17' <?php if ($arts[id_tipo] == 17) {echo selected;} ?>>Usados</option>
                  <option value='18' <?php if ($arts[id_tipo] == 18) {echo selected;} ?>>Notekooks</option>
                  <option value='19' <?php if ($arts[id_tipo] == 19) {echo selected;} ?>>Otros</option>
                </select></td>
            </tr>
            <tr> 
              <td>Caracteristica:</td>
              <td><textarea rows="10" name="caract" cols="50"><?php echo $arts[caract]; ?></textarea> 
                <strong>Campo Obligatorio. Max. 500</strong></td>
            </tr>
            <tr> 
              <td>Descripcion:</td>
              <td><textarea rows="10" name="info" cols="50"><?php echo $arts[info]; ?></textarea></td>
            </tr>
            <tr> 
              <td>Precio:</td>
              <td><input name=precio type=text value="<?php if ($arts) { echo $arts[precio];} else { echo 'U$S ';} ?>" maxlength="11"></td>
            </tr>
            <tr> 
              <td>Novedad:</td>
              <td> <b> 
                <input type="radio" value="1" name="novedad"  <?php if ($arts[novedad] == 1) {echo "checked";} ?>>
                <font size="2">Si</font></b> <b> 
                <input type="radio" value="0" name="novedad" <?php if ($arts[novedad] == 0) {echo "checked";} ?>>
                <font size="2">No</font></b> </td>
            </tr>
            <tr> 
              <td>Stock:</td>
              <td> <b> 
                <input type="radio" value="1" name="stock" <?php if ($arts[stock] == 1) {echo "checked";} ?>>
                <font size="2">Si</font></b> <b> 
                <input type="radio" value="0" name="stock" <?php if ($arts[stock] == 0) {echo "checked";} ?>>
                <font size="2">No</font></b> </td>
            </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td><div align="center"><img src="../../images/articulos/<?php echo $arts[foto?>" width="130" height="100"></div></td>
                </tr>
                <tr> 
            <tr> 
              <td>Foto 1:</td>
              <td> <input type=file name=file> </td>
            </tr>
               <tr>
                  <td>&nbsp;</td>
                  <td><div align="center"><img src="../../images/articulos/<?php echo $arts[foto2?>" width="130" height="100"></div></td>
                </tr>
                <tr> 
            <tr> 
              <td>Foto 2:</td>
              <td> <input type=file name=file2> </td>
            </tr>

                <tr>
                  <td>&nbsp;</td>
                  <td><div align="center"><img src="../../images/articulos/<?php echo $arts[foto3?>" width="130" height="100"></div></td>
                </tr>
                <tr> 
            <tr> 
              <td>Foto 3:</td>
              <td> <input type=file name=file3> <input name="foto" type="hidden" value="<? echo $arts[foto]; ?>"> 
                <input name="foto2" type="hidden" value="<? echo $arts[foto2]; ?>"> 
                <input name="foto3" type="hidden" value="<? echo $arts[foto3]; ?>"> 
                <input name="idss" type="hidden" value="<? echo $edis?>"> </td>
            </tr>
            <tr> 
              <td colspan=2 align=center><br> <input type=submit value="  Modificar  "> 
              </td>
            </tr>
          </table>
</form>
<?php }else{ ?>
<table width="764" border="0" cellpadding="0">
  <tr>
    <td width="760" align="center" class="text12">
<table width="760" border="0" cellpadding="3" cellspacing="0" class="text11">
        <tr bgcolor="#CCCCCC"> 
                  <td width="100%" class="text11"><strong><font color="#000000">Agregar 
                    Articulo </font></strong></td>
        </tr>
      </table>
... Sigue por el tema de caracteres.

Última edición por Jer.; 03/06/2006 a las 10:46
  #2 (permalink)  
Antiguo 03/06/2006, 10:12
 
Fecha de Ingreso: junio-2006
Mensajes: 15
Antigüedad: 17 años, 9 meses
Puntos: 0
Código PHP:
<table width="464" border="1">
  <tr>
    <td width="454"><form method=post action=in.php?action=register enctype="multipart/form-data">
<table align="center">
<tr><td>Nombre:</td><td><input name=nombre type=text size="50" maxlength="255"></td></tr>
<tr><td>Web Review:</td><td><input name=pagrev type=text value="h**p://" size="50" maxlength="255"></td></tr>
<tr><td>Web Oficial:</td><td><input name=pagofi type=text value="h**p://" size="50" maxlength="255"></td></tr>
<tr><td>Rubro:</td>
      <td><select name="id_tipo">
          <option value="0" selected>- Rubro -</option>
            <option value='1'>Procesadores</option>
            <option value='2'>Motherboards</option>
            <option value='3'>Memorias</option>
            <option value='4'>Placas de Video</option>
            <option value='5'>Fuentes</option>
            <option value='6'>Gabinetes</option>
            <option value='7'>Discos Rigidos</option>
            <option value='8'>Coolers</option>
            <option value='9'>Equipos Armados</option>
            <option value='10'>Reproductores MP3</option>
            <option value='11'>Parlantes </option>
            <option value='12'>Monitores</option>
            <option value='13'>Mouse y Teclado</option>
            <option value='14'>Combos</option>
            <option value='15'>Impresoras</option>
            <option value='16'>Opticos</option>
            <option value='17'>Usados</option>
            <option value='18'>Notekooks</option>
            <option value='19'>Otros</option>
        </select></td>
    </tr>
<tr><td>Caracteristica:</td><td><textarea rows="10" name="caract" cols="50">
</textarea>
                    <strong>Campo Obligatorio. Max. 500</strong></td>
                </tr>
<tr><td height="186">Descripcion:</td><td><textarea rows="10" name="info" cols="50">
</textarea></td></tr>
<tr><td>Precio:</td><td><input name=precio type=text value="U$S " maxlength="11"></td></tr>
<tr><td>Novedad:</td><td>
<b><input type="radio" value="1" name="novedad" checked> <font size="2">Si</font></b>
        <b><input type="radio" value="0" name="novedad"> <font size="2">No</font></b>
          </td>
          </tr>
<tr><td>Stock:</td><td>
<b><input type="radio" value="1" name="stock" checked> <font size="2">Si</font></b>
        <b><input type="radio" value="0" name="stock"> <font size="2">No</font></b>
          </td>
          </tr>
<tr><td>Foto 1:</td><td>

      <input type=file name=file>
          </td>
          </tr>
<tr><td>Foto 2:</td><td>

      <input type=file name=file2>
          </td>
          </tr>
<tr><td>Foto 3:</td><td>

      <input type=file name=file3>

          </td>
          </tr>
<tr><td colspan=2 align=center><br><input type=submit value="  Mandar  ">&nbsp;&nbsp;<input name="Reset" type=reset value="Borrar todo"></td></tr>
</table>
</form>

<?
// fin if de edit
if ($action == register) {
$nombre $_POST["nombre"];
$pagrev $_POST["pagrev"];
$pagofi $_POST["pagofi"];
$id_tipo $_POST["id_tipo"];
$info $_POST["info"];
$caract $_POST["caract"];
$precio $_POST["precio"];
$novedad $_POST["novedad"];
$stock $_POST["stock"];


  if (!
$nombre || !$info || !$precio || !$caract) {
    echo 
"<center><font color=#FF0000 size=5><strong></p>Tenes que completar todos los campos.</strong></font></center>";

 } else {

// Directorio        
$destino '../../images/articulos' ;
if (
$file) {

/*        File 1             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file']['type'];

 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck '.gif'; }
 if (
$type == 'image/jpeg') { $fuck '.jpg'; }
 if (
$type == 'image/bmp') { $fuck '.bmp'; }
 
$unique_id md5(uniqid(time()));
  
$filename $unique_id $fuck;
move_uploaded_file $_FILES 'file' ][ 'tmp_name' ], $destino '/' $unique_id $fuck);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 1" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 1" ; }
}

if (
$file2) {

/*        File 2             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file2' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file2']['type'];
 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck2 '.gif'; }
 if (
$type == 'image/jpeg') { $fuck2 '.jpg'; }
 if (
$type == 'image/bmp') { $fuck2 '.bmp'; }
 
$unique_id2 md5(uniqid(time()));
  
$filename2 $unique_id2 $fuck2;
move_uploaded_file $_FILES 'file2' ][ 'tmp_name' ], $destino '/' .  $unique_id2 $fuck2);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 2" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 2" ; }
}

if (
$file3) {

/*        File 3             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file3' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file3']['type'];

 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck3 '.gif'; }
 if (
$type == 'image/jpeg') { $fuck3 '.jpg'; }
 if (
$type == 'image/bmp') { $fuck3 '.bmp'; }
 
$unique_id3 md5(uniqid(time()));
 
$filename3 $unique_id3 $fuck3;
move_uploaded_file $_FILES 'file3' ][ 'tmp_name' ], $destino '/' .  $unique_id3 $fuck3);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 3" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 3" ; }
}


    
mysql_query("insert into articulos ( `id` , `stock` , `nombre` , `precio` , `pagrev` , `pagofi` , `info` , `caract` , `novedad` , `foto` , `foto2` , `foto3` , `id_tipo` ) values ('', '$stock', '$nombre', '$precio', '$pagrev', '$pagofi', '$info','$caract', '$novedad', '$filename', '$filename2', '$filename3', '$id_tipo')") or die("No se pudo mandar la informacion, reintente mas tarde.");
        
                
    echo 
"<center><strong><font color=#0000FF size=+2>Los datos fueron guardados en la base de datos.</font></strong></center>";



    echo 
"<center><br><a href=index.php>Volver atras</a></center>";


   } 
//fin del if para ver si esta todo
}

if (
$action == edit) {
$nombreq $_POST["nombre"];
$pagrevq $_POST["pagrev"];
$pagofiq $_POST["pagofi"];
$id_tipoq $_POST["id_tipo"];
$infoq $_POST["info"];
$caractq $_POST["caract"];
$precioq $_POST["precio"];
$novedadq $_POST["novedad"];
$stockq $_POST["stock"];
$fotoq $_POST["foto"];
$foto2q $_POST["foto2"];
$foto3q $_POST["foto3"];
$edisq $_POST["idss"];


// Directorio        
$destino '../../images/articulos' ;
if (
$file) {

/*        File 1             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file']['type'];

 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck '.gif'; }
 if (
$type == 'image/jpeg') { $fuck '.jpg'; }
 if (
$type == 'image/bmp') { $fuck '.bmp'; }
 
$unique_id md5(uniqid(time()));
  
$filenameq $unique_id $fuck;
move_uploaded_file $_FILES 'file' ][ 'tmp_name' ], $destino '/' $unique_id $fuck);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 1" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 1" ; }
} else { 
$filenameq $fotoq; }

if (
$file2) {

/*        File 2             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file2' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file2']['type'];
 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck2 '.gif'; }
 if (
$type == 'image/jpeg') { $fuck2 '.jpg'; }
 if (
$type == 'image/bmp') { $fuck2 '.bmp'; }
 
$unique_id2 md5(uniqid(time()));
  
$filename2q $unique_id2 $fuck2;
move_uploaded_file $_FILES 'file2' ][ 'tmp_name' ], $destino '/' .  $unique_id2 $fuck2);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 2" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 2" ; }
} else { 
$filename2q $foto2q; }

if (
$file3) {

/*        File 3             */
// Leemos el tamaño del fichero
$tamano $_FILES 'file3' ][ 'size' ];
// Comprovamos el tamaño
if( $tamano 850000 ){
$type $_FILES['file3']['type'];

 if (
$type == 'image/gif' or $type == 'image/jpeg' or  $type == 'image/bmp'){
 if (
$type == 'image/gif') { $fuck3 '.gif'; }
 if (
$type == 'image/jpeg') { $fuck3 '.jpg'; }
 if (
$type == 'image/bmp') { $fuck3 '.bmp'; }
 
$unique_id3 md5(uniqid(time()));
 
$filename3q $unique_id3 $fuck3;
move_uploaded_file $_FILES 'file3' ][ 'tmp_name' ], $destino '/' .  $unique_id3 $fuck3);
} else { echo 
"El tipo de archivo no es permitido. De la Foto 3" ; }
} else { echo 
"El tamaño es superior al permitido. De la Foto 3" ; }
} else { 
$filename3q $foto3q; }

    
mysql_query("UPDATE `articulos` SET  
    `stock` = '$stockq',
    `nombre` = '$nombreq',
    `precio` = '$precioq',
    `pagrev` = '$pagrevq',
    `pagofi` = '$pagofiq',
    `info` = '$infoq',
    `novedad` = '$novedadq',
    `caract` = '$caractq',
    `foto` = '$filenameq',
    `foto2` = '$filename2q',
    `foto3` = '$filename3q',
    `id_tipo` = '$id_tipoq' 
            WHERE `id` = $edisq LIMIT 1 ;"
) or die ("No se pudo mandar la informacion, reintente mas tarde.");
        
                
    echo 
"<center><strong><font color=#0000FF size=+2>Los datos fueron modificados con exito.</font></strong></center>";



    echo 
"<center><br><a href=index.php>Volver a Articulos</a></center>";


}
?>
</td>
  </tr>
</table>

<table width="760" border="0" cellpadding="3" cellspacing="0" class="text11">
        <tr bgcolor="#CCCCCC"> 
          <td colspan="5" class="text11">&nbsp;</td>
        </tr>
        
      </table>

</td>
  </tr></table>
<? include ("../inc/admin_bot.php")?>
</body>
</html>

Desde ya muchas gracias
  #3 (permalink)  
Antiguo 03/06/2006, 10:40
pablasso
Invitado
 
Mensajes: n/a
Puntos:
seria un poco mas facil si nos dijeras que es lo que falla antes de leer todo
  #4 (permalink)  
Antiguo 03/06/2006, 10:46
 
Fecha de Ingreso: junio-2006
Mensajes: 15
Antigüedad: 17 años, 9 meses
Puntos: 0
:D tenes Razon el sistema de subir Archivos!!! (inventado :P) Sube cuando quiere!!
  #5 (permalink)  
Antiguo 03/06/2006, 10:55
pablasso
Invitado
 
Mensajes: n/a
Puntos:
seria bueno que checaras el php.ini y ves los maximos permitidos para archivos subidos y el tiempo de ejecucion, puede que a veces lo estes excediendo

seria muy util que nos dijeras el output que te dice cuando falla, o tratar de usar el output de funciones como move_uploaded_file que si mal no recuerdo te regresa "false" si falla, ya que simplemente puede ser problemas de permisos en la carpeta donde intentas subir
  #6 (permalink)  
Antiguo 03/06/2006, 11:18
 
Fecha de Ingreso: junio-2006
Mensajes: 15
Antigüedad: 17 años, 9 meses
Puntos: 0
pablasso perdon como haria esto q me dices
  #7 (permalink)  
Antiguo 03/06/2006, 11:23
 
Fecha de Ingreso: julio-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.304
Antigüedad: 18 años, 8 meses
Puntos: 6
Haces un archivo con el siguiente codigo, y lo ves como cualquier otro .php

Código PHP:
<?php phpinfo(); ?>
En lo que te muestre, busca upload_max_filesize y te fijas cuanto dice.

Saludos!
__________________
Federico.

Mi página: www.jourmoly.com.ar
  #8 (permalink)  
Antiguo 03/06/2006, 11:36
 
Fecha de Ingreso: junio-2006
Mensajes: 15
Antigüedad: 17 años, 9 meses
Puntos: 0
2M tiene.....
  #9 (permalink)  
Antiguo 03/06/2006, 17:41
 
Fecha de Ingreso: julio-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.304
Antigüedad: 18 años, 8 meses
Puntos: 6
Pues fijate si las veces que 'falla' la subida coincide con que el archivo que intentas subi pesa mas de 2M. Es muy probable, muchas veces me ha pasado.

Algunos Servicios de Hosting, si contactas con el soporte tecnico te lo pueden subir, en mi caso, me lo suben a 20MB. Si quieres consultarlo, pregunta por el "upload_max_filesize"

Suerte!
__________________
Federico.

Mi página: www.jourmoly.com.ar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:39.