|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  Raspberry Pi Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  AutoIt (Programación) Visual Basic Cosas de Windows Webs interesantes
Translate:
Búsqueda en este sitio:


.

Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando

-- Tutorial de iniciación a Autoit --

Volver al índice del tutorial

____________________________

70.- Crear archivo de texto y subirlo a un servidor. Bajarlo, modificarlo y volverlo a subir.

- Escribimos un texto en un Edit1 ("El Ñandú corrió por Cádiz"), le ponemos un nombre de archivo (ejemplo.txt). Lo subimos a un servidor remoto.

- Pulsamos un botón2, indicamos el archivo que queremos bajar (ejemplo.txt), el archivo bajará, se guardará en la carpeta Documentos y se verá su contenido en un Edit1.

_______________________________________________________
1.- Necesitamos un hosting.

- Lee este tutorial y créate una cuenta gratuita en Hostinger.

- Además aprende a subir archivos a Hostinger mediante el cliente de FTP Mozilla.

317.- Hosting gratuito Hostinger.

_____________________________________________________
2.- Archivo PHP que subiremos a nuestro hosting.

enviar_archivo.php
			   
<?php
// Juan Antonio Villalpando.
// KIO4.COM

$datos = $_POST;
$contenido = $datos['contenido'];
$nombre = $datos['nombre'];

$auxi = fopen($nombre, 'w');
fwrite($auxi, $contenido); 
fclose($auxi);

echo "Archivo subido.";

?>

- Este PHP será el encargado de tomar la información de texto que se envía mediante "dato" y guardarlo en el servidor remoto.

_____________________________________________________
3.- Aplicación en AutoIt para enviar los datos y guardarlo como archivo. También para bajarlo.

- Enviará un mensaje al servidor remoto y mediante PHP insertará la información.

Código para el AutoIt
				   
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <InetConstants.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Subir archivo - Juan A. Villalpando", 584, 531, 697, 180)
$Label1 = GUICtrlCreateLabel("Escribe el contenido del archivo:", 48, 24, 198, 20)
$Edit1 = GUICtrlCreateEdit("", 56, 64, 473, 137, BitOr($WS_VSCROLL, $ES_MULTILINE, $WS_TABSTOP))
GUICtrlSetData(-1, "El Ñandú corrió por Cádiz.")
$Button1 = GUICtrlCreateButton("Enviar", 56, 304, 481, 41)
$Label3 = GUICtrlCreateLabel("Label3", 80, 376, 200, 40)
$Label2 = GUICtrlCreateLabel("Nombre del archivo: ", 56, 248, 128, 20)
$Input1 = GUICtrlCreateInput("ejemplo.txt", 200, 240, 161, 24)
$Button2 = GUICtrlCreateButton("Bajar", 64, 424, 465, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$contenido = ""
$nombre = ""

While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop


    ; Botón SUBIR
    Case $msg = $Button1
    $contenido = GUICtrlRead($Edit1)
    $nombre = GUICtrlRead($Input1)
    $datos = "contenido=" & $contenido & "&nombre=" & $nombre
    enviar()
    Beep(900,500)
    GUICtrlSetData($Edit1, "")

    ; Botón BAJAR
    Case $msg = $Button2
    bajar()

EndSelect
Wend
Exit

; Enviar archivo
Func enviar()
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://kio4.esy.es/enviar_archivo.php", False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$oHTTP.Send($datos)
; Recibir información
$Respuesta = $oHTTP.ResponseText
$Codigo = $oHTTP.Status

Beep(400,500)
GUICtrlSetData($Label3,$Respuesta)
Sleep(2000)
GUICtrlSetData($Label3,"") ; Borra Label3
EndFunc

Func bajar()
; Copiar el archivo en la carpeta de Documentos.
$sReturn = InetRead("http://kio4.esy.es/" & $nombre) ; El nombre del Input1
$hFile = FileOpen(@DocumentsCommonDir & "\archivo_bajado.txt", 2+16) ; Se guardará en Documentos
FileWrite(@DocumentsCommonDir & "\archivo_bajado.txt", $sReturn)
FileClose($hFile)

; Poner el archivo en el Edit1
$file = @DocumentsCommonDir & "\archivo_bajado.txt"
FileOpen($file, 0)
$line =""
For $i = 1 to _FileCountLines($file)
    $line = $line & FileReadLine($file, $i) & @CR
Next
GUICtrlSetData($Edit1, $line)
FileClose($file)
EndFunc

_____________________________________________________
- Propuesta.

- Los cambios de líneas no se ven cuando baja el archivo, intenta arreglarlo.

- Pero sí se ven en el archivo que has bajada a Documentos.

mark2004 said:
Thanks for that. It definitely works. I just need to read up on using Accelerators and Dummy controls before I fully understand what you did.....
Accelerators are like HotKeySet() except that they work only when your GUI is active.
Accelerators however are tied to controls as opposed to functions.
So, we create a dummy control to be fired by the accelerator & poll for that in our GuiGetMsg loop.
From there, it's check which control has the focus when the accelerator (ENTER) is hit. If its the control we want to act on, call our custom function.
If the focus isn't on the control we want, turn off the accelerator(s), ControlSend() the regular action of the key used as the accelerator to the current control, then turn the accelerator(s) back on.
We turn the accelerator(s) off and then back on so we don't get stuck in a loop of sending {ENTER} all the time.
Credit for the use of dummy controls with Accelerators goes to Zedna http://www.autoitscript.com/forum/index.ph...st&p=493696

_______________________________________________

_________________

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información