Jump to content

Upload files to www ERROR


Recommended Posts

Hello,

Anyone can help me what is wrong here?

I have found an function, but I don't know my file isn't uploading to server WWW.

Here is function Autoit:

#include <HTTP.au3>

$host = "www.test.ovh"
$port = "80"
$page = "test.php"
$vars = "action=upload"

$url = $page&"?"&_HTTPEncodeString($vars)

$file = FileOpen("testuploadfile.txt", 2)
$tmp = FileRead($file)
$data = $tmp
FileClose($file)

$socket = _HTTPConnect($host, $port)
$get = _HTTPPost_File($host,$url,$socket,$data, "testuploadfile.txt");note the custom function below
$recv = _HTTPRead($socket,1)
MsgBox(0, "Info", "Data received:" & @CRLF & $recv[4] & @CRLF)


Func _HTTPPost_File($host, $page, $socket = -1, $data = "", $filename = "")
    Dim $command

    If $socket == -1 Then
        If $_HTTPLastSocket == -1 Then
            SetError(1)
            Return
        EndIf
        $socket = $_HTTPLastSocket
    EndIf

    Dim $datasize = StringLen($data)

    $command = "POST "&$page&" HTTP/1.1"&@CRLF
    $command &= "Host: " &$host&@CRLF
    $command &= "User-Agent: "&$_HTTPUserAgent&@CRLF
    $command &= "Accept: text/html,application/xhtml+xml,application/xml"&@CRLF
    $command &= "Accept-Encoding: gzip,deflate"&@CRLF
    $command &= "Keep-Alive: 300"&@CRLF
    $command &= "Connection: keep-alive"&@CRLF
    $command &= "Content-Type: multipart/form-data; boundary=---------------------------121082565914826020141098229367"&@CRLF
    $command &= "Content-Length: "&$datasize&@CRLF
    $command &= ""&@CRLF
    $command &= "---------------------------121082565914826020141098229367"&@CRLF
    $command &= "Content-Disposition: form-data; name=uploadedfile; filename=" & $filename &@CRLF
    $command &= "Content-Type: text/plain"&@CRLF
    $command &= ""&@CRLF
    $command &= $data&@CRLF
    $command &= "---------------------------121082565914826020141098229367--"&@CRLF

    MsgBox(0, "HTTP Headers", $command)

    Dim $bytessent = TCPSend($socket, $command)

    If $bytessent == 0 Then
        SetExtended(@error)
        SetError(2)
        return 0
    EndIf

    SetError(0)
    Return $bytessent
EndFunc

PHP FILE test.php

if($_GET['action'] == 'upload'){
$target_path = "/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
}

Please help me.

Regards

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...