SA-MP Forums Archive
HTTP_POST - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: HTTP_POST (/showthread.php?tid=385121)



HTTP_POST - 2KY - 14.10.2012

How would I go about using this to connect to a FTP (basically) and write a file?


Re: HTTP_POST - Azazelo - 14.10.2012

You may use php (i think this is the quick way)

Use: fwrite instead ftp_connect may be faster way for small amount of data(not sure but work for me)



PHP код:
Example #1 A simple fwrite() example
<?php
$filename 
$_GET["filename"];
$somecontent $_GET["somecontent"] . "\n" ;

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    
// In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    
if (!$handle fopen($filename'a')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
        echo 
"Cannot write to file ($filename)";
        exit;
    }

    echo 
"Success, wrote ($somecontent) to file ($filename)";

    
fclose($handle);

} else {
    echo 
"The file $filename is not writable";
}
?>
And you use HTTP_GET in this case
Quote:

new urllink[512 char];
urllink = "www.myphp.info/writefile.php?filename='youfile.txt'&somecontent=' youdata'";
HTTP(playerid, HTTP_GET,urllink, "", "MyHttpResponse");

More info:
Quote:
https://sampwiki.blast.hk/wiki/HTTP
http://php.net/manual/en/function.fwrite.php
http://php.net/manual/en/function.ftp-connect.php
Edit:And this is not the best or right way to do it.