Sign in to follow this  
Followers 0
Maches

Upload files to www ERROR

4 posts in this topic

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

Share this post


Link to post
Share on other sites



What is your file size? check your WebServer log file to see if there is an error, and check your php.ini config file because the default one allow only small file to be upload.

Share this post


Link to post
Share on other sites

File size is 1 kb?... it's txt document.

Ok,I will do that, but in code is all alright?

Share this post


Link to post
Share on other sites

your code is ok. 

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