Foros del Web » Programando para Internet » PHP »

Guardar y descargar un archivo .txt proveniente den textarea

Estas en el tema de Guardar y descargar un archivo .txt proveniente den textarea en el foro de PHP en Foros del Web. Hola, necesito guardar en un archivo .txt el contenido de text area y de una vez descargarlo, pero no se como ??? alguna sugerencia. muchas ...
  #1 (permalink)  
Antiguo 03/12/2009, 10:55
 
Fecha de Ingreso: diciembre-2009
Mensajes: 11
Antigüedad: 14 años, 4 meses
Puntos: 0
Guardar y descargar un archivo .txt proveniente den textarea

Hola, necesito guardar en un archivo .txt el contenido de text area y de una vez descargarlo, pero no se como ??? alguna sugerencia.

muchas gracias
  #2 (permalink)  
Antiguo 03/12/2009, 11:00
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: Guardar y descargar un archivo .txt proveniente den textarea

Hola Novataa

Con JavaScript no se puede leer ni escribir archivos. Necesitarás un lenguaje del lado del servidor (PHP, ASP...). Dinos cual quieres usar para mover el mensaje al foro que corresponda.

Saludos,
  #3 (permalink)  
Antiguo 03/12/2009, 12:11
 
Fecha de Ingreso: diciembre-2009
Mensajes: 11
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Guardar y descargar un archivo .txt proveniente den textarea

Hola PHP esta biennn gracias.
  #4 (permalink)  
Antiguo 03/12/2009, 12:12
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Tema movido al foro de PHP desde Javascript.

Saludos,
  #5 (permalink)  
Antiguo 03/12/2009, 23:34
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 10 meses
Puntos: 834
Respuesta: Guardar y descargar un archivo .txt proveniente den textarea

En realidad en javascript podés hacer esto (funciona en todos los navegadores excepto en chrome):
Código PHP:
<!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>Documento sin t&iacute;tulo</title>
<
script type="text/javascript">
/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
    
// private property
    
_keyStr "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
    
// public method for encoding
    
encode : function (input) {
        var 
output "";
        var 
chr1chr2chr3enc1enc2enc3enc4;
        var 
0;
 
        
input Base64._utf8_encode(input);
 
        while (
input.length) {
 
            
chr1 input.charCodeAt(i++);
            
chr2 input.charCodeAt(i++);
            
chr3 input.charCodeAt(i++);
 
            
enc1 chr1 >> 2;
            
enc2 = ((chr1 3) << 4) | (chr2 >> 4);
            
enc3 = ((chr2 15) << 2) | (chr3 >> 6);
            
enc4 chr3 63;
 
            if (
isNaN(chr2)) {
                
enc3 enc4 64;
            } else if (
isNaN(chr3)) {
                
enc4 64;
            }
 
            
output output +
            
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
        }
 
        return 
output;
    },
 
    
// public method for decoding
    
decode : function (input) {
        var 
output "";
        var 
chr1chr2chr3;
        var 
enc1enc2enc3enc4;
        var 
0;
 
        
input input.replace(/[^A-Za-z0-9+/=]/g"");
 
        while (
input.length) {
 
            
enc1 this._keyStr.indexOf(input.charAt(i++));
            
enc2 this._keyStr.indexOf(input.charAt(i++));
            
enc3 this._keyStr.indexOf(input.charAt(i++));
            
enc4 this._keyStr.indexOf(input.charAt(i++));
 
            
chr1 = (enc1 << 2) | (enc2 >> 4);
            
chr2 = ((enc2 15) << 4) | (enc3 >> 2);
            
chr3 = ((enc3 3) << 6) | enc4;
 
            
output output String.fromCharCode(chr1);
 
            if (
enc3 != 64) {
                
output output String.fromCharCode(chr2);
            }
            if (
enc4 != 64) {
                
output output String.fromCharCode(chr3);
            }
 
        }
 
        
output Base64._utf8_decode(output);
 
        return 
output;
 
    },
 
    
// private method for UTF-8 encoding
    
_utf8_encode : function (string) {
        
string string.replace(/rn/g,"\n");
        var 
utftext "";
 
        for (var 
0string.lengthn++) {
 
            var 
string.charCodeAt(n);
 
            if (
128) {
                
utftext += String.fromCharCode(c);
            }
            else if((
127) && (2048)) {
                
utftext += String.fromCharCode((>> 6) | 192);
                
utftext += String.fromCharCode((63) | 128);
            }
            else {
                
utftext += String.fromCharCode((>> 12) | 224);
                
utftext += String.fromCharCode(((>> 6) & 63) | 128);
                
utftext += String.fromCharCode((63) | 128);
            }
 
        }
 
        return 
utftext;
    },
 
    
// private method for UTF-8 decoding
    
_utf8_decode : function (utftext) {
        var 
string "";
        var 
0;
        var 
c1 c2 0;
 
        while ( 
utftext.length ) {
 
            
utftext.charCodeAt(i);
 
            if (
128) {
                
string += String.fromCharCode(c);
                
i++;
            }
            else if((
191) && (224)) {
                
c2 utftext.charCodeAt(i+1);
                
string += String.fromCharCode(((31) << 6) | (c2 63));
                
+= 2;
            }
            else {
                
c2 utftext.charCodeAt(i+1);
                
c3 utftext.charCodeAt(i+2);
                
string += String.fromCharCode(((15) << 12) | ((c2 63) << 6) | (c3 63));
                
+= 3;
            }
 
        }
 
        return 
string;
    }
 
}
function 
salvar(t){
    if(
window.ActiveXObject){
        var 
v=window.open('','pp','');
        
v.document.open();
        
v.document.write(t+'<scr'+'ipt>document.execCommand("SaveAs",null,"archivo.txt");</scr'+'ipt>');
        
v.document.close();
    }else{
        if(
typeof btoa=='function')
            
window.location='data:application/octet-stream;base64,'+btoa(t);
        else
            
window.location='data:application/octet-stream;base64,'+Base64.encode(t);
    }
}

</script>
</head>

<body>
<form id="form1" name="form1">
  <textarea name="textarea" cols="80" rows="5" id="textarea"></textarea>
  <input onclick="salvar(textarea.value)" type="button" name="Submit" value="descargar como txt" id="Submit" />
</form>
<iframe id="pp" name="pp" style="position:absolute; left:-1500px" />
</body>
</html> 
  #6 (permalink)  
Antiguo 04/12/2009, 10:30
 
Fecha de Ingreso: diciembre-2009
Mensajes: 11
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Guardar y descargar un archivo .txt proveniente den textarea

Muuuchas GRaciasss, me funciona solo con el activeX.
lo del Base 64 me asusto un poco, pero ya medio entiendo, GRACIAS
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:59.