Ver Mensaje Individual
  #12 (permalink)  
Antiguo 25/02/2008, 15:43
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Re: ¿gif de carga mientras se sube una foto?

Simplifiqué un poco el código y lo puse todo en la misma página (luego colocalo como necesites). Pero sería algo así:
Código PHP:
<?php
if($_FILES['archivo']){
    if(
102400 $_FILES['archivo']['size']){
        
$tmp $_FILES['archivo']['tmp_name'];
        
$name $_FILES['archivo']['name'];
        if(
move_uploaded_file($tmp$name)){
            echo 
'
            <script>
            parent.document.getElementById("loading").style.display="none";
            parent.document.getElementById("mensaje").innerHTML="Archivo grabado correctamente";
            old_f=parent.document.getElementById("archivo");
            new_f=parent.document.createElement("input");
            new_f.type="file";
            new_f.name="archivo";
            new_f.value="";
            new_f.id="archivo";
            new_f.className="campoArchivo";
            old_f.parentNode.replaceChild(new_f,old_f);
            </script>'
;
            exit;
        }
    }
echo 
'
            <script>
            parent.document.getElementById("loading").style.display="none";
            parent.document.getElementById("mensaje").innerHTML="El archivo no pudo grabarse.";
            old_f=parent.document.getElementById("archivo");
            new_f=parent.document.createElement("input");
            new_f.type="file";
            new_f.name="archivo";
            new_f.value="";
            new_f.id="archivo";
            new_f.className="campoArchivo";
            old_f.parentNode.replaceChild(new_f,old_f);
            </script>'
;
exit;
}
?>
<!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>test</title>
<style>
.campoArchivo{font-family: Verdana; font-size: 8pt; border: 1px solid #C0C0C0}
</style>
</head>

<body><form target="pepe" method="post" enctype="multipart/form-data" action="<?php echo basename($_SERVER['PHP_SELF'])?>" onsubmit="if(document.getElementById('archivo').value.length)document.getElementById('loading').style.display='inline'">
<table width="100%" style="margin: auto;">
<tr>
<td style="width: 27%;"><div id="mensaje" style="font-family:Verdana, Arial, Helvetica, sans-serif; color:red"></div></td>
</tr>
<tr>
<td style="width: 27%;">
<p align="center">
<input type="file" name="archivo" id="archivo" size="26" class="campoArchivo" />
<input type="submit" value="Cargar archivo" style="font-family: Verdana; font-size: 7pt; border: 1px solid #808080; " />
&nbsp;<img id="loading" src="ajaxloader.gif" width="16" height="16" style="display:none" /></td>
</tr>
</table>
</form>
<iframe name="pepe" width="1" height="1" style="visibility:hidden"></iframe>
</body>
</html>
Notar el iframe, su nombre y el target del formulario. ajaxloader.gif puede ser la imagen sugerida por caricatos ()

Última edición por Panino5001; 25/02/2008 a las 16:12