Sign in to follow this  
Followers 0
rCANE

Upload files through PHP to a webserver

7 posts in this topic

hi guys!

i have a basic gui.

i want 2 things.

1. upload a simple text file to a webserver. so there is a 10 kb text file ( mytext.txt ) and i want to send to the PHP to upload to the server ( www.mydomainaddress.com/upload.php ) i want progress/status infos about the uploading process ( the percentage, when completed tell me it's done, when erroroccurs tell me and if it's possible show the uploading speed )

2. then i want to upload a jpg file... ( myimg.jpg ) send to the PHP ( www.mydomainaddress.com/upload.php ) and the same detailed status infos about the uploading process ( percentage,error handling,completed,speed ). the jpegs are between 350 kb and 1500 kb.

is this posibble to do with autoit?

if it is very big THX for an example code.

thanks guys

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It is possible, however if you're new to Autoit it could be challenging. Look at the TCP functions, they give the most control but they're more advanced. Then there's IE automation which I'm not sure would provide enough information for statistics. Look into it.

Btw, there's no difference what type of file is sent. And you might want to provide the full link so people can check out that php upload script, in case you want examples.

Edited by Datenshi

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thank you for your answer

...the PHP for upload is based on this ( the only diff are file types and folders )

i've found this topic, but how can i address my webserver's php when i send a file?

what socket and ip should i use?

...and that topic's example can give me somehow a detailed statistics?

Edited by rCANE

Share this post


Link to post
Share on other sites

i copy/pasted some AutoIt code, but i can't find how to address the PHP file :D

TCPStartup()
$host = 'localhost'
$IP = TCPNameToIp($host)
$Socket = TCPConnect($IP,80)

$Send = TCPSend($Socket,'the text to send')
; the path to the PHP file is: localhost/devscripts/upload/wm_upload.php

PHP:

<?php
    $path = "wm_upload_dir/";
     
    if ($_FILES["file"]["size"] < 2000000) {    
       if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        } else {
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
        if (file_exists($path . $_FILES["file"]["name"])) {
            echo $_FILES["file"]["name"] . " already exists. ";
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"],
            $path . $_FILES["file"]["name"]);
            echo "Stored in: " . $path . $_FILES["file"]["name"];
        }
        }
    } else {
        echo "Invalid file";
    }
?>

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

i copy/pasted some AutoIt code, but i can't find how to address the PHP file :D

TCPStartup()
$host = 'localhost'
$IP = TCPNameToIp($host)
$Socket = TCPConnect($IP,80)

$Send = TCPSend($Socket,'the text to send')
; the path to the PHP file is: localhost/devscripts/upload/wm_upload.php

Hi,

I saw your PM, so here I go. I'll explain what you need to do and why, you can do the code stuff yourself. :huggles:

Since HTTP is based on TCP, you have to do your own HTTP requests and answer the HTTP responses received from the server.

So, as you do, you setup a TCP connection on port 80 and then follow the following example http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Example_session

This example isn't going to send a file to the server, but once you are able to get this working, it won't be difficult to get to upload a file.

An interresting one: http://www.vbforums.com/showthread.php?t=337424

You need to deepen out this more yourself, but I hope the concept is clear. I could make an example, but you will learn more by deepen this out yourself.

Let's make this interesting for both of us. If you deepen this out more, by providing more information or code, than I'll post a working one :

Edited by Pakku

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmm, what about a HTTP UDF? None found on the forum, would one like to develop one with me?

Check below, it is exacly what you need.

Edited by Pakku

Share this post


Link to post
Share on other sites

I made an example for WinHTTP: http://www.autoitscript.com/forum/index.php?showtopic=84133&view=findpost&p=610967

(Not sure if the example with imageshack is correct, but the function i use is still working)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0