ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-gtk-general
php-gtk-general
Re: [PHP-GTK] POST file transfer
by Gwyn Morfey other posts by this author
Oct 31 2002 8:53AM messages near this date
[PHP-GTK] POST file transfer | [PHP-GTK] Agata Report: new version
Hi -

I found this on the net somewhere and hacked it a bit. Call it with:
	$arr = array( "mydata" =>  $mydata);
	$reply = post_data ($host,$url,$arr,$port);

The target script will get $HTTP_POST_VARS["mydata"];

Hope this helps,

Gwyn.

----
// post data and return reply
function post_data ($host, $url, $data, $port=80) {
	//echo "Post data";
	// INPUT VALIDATION:
	if (strlen($host)<1)
		return false;

	if (strlen($url)<1)
		return false;

	if ((!is_array($data)) || sizeof($data)<1) {
		//echo "Not an array.";
		return false;
	}

	//echo "Socket opening";
	$fp = fsockopen ($host, $port, $errno, $errstr, 120);
	$ret = "";
	//if (strncasecmp ($url, "http://", 7) == 0) $url = substr ($url, 7);

	$req = substr ($url, $p);

	if ($fp)
		{
		//echo "FP okay";
		fputs ($fp, "POST $req HTTP/1.0\n");
		post_send_headers ($fp);
		fputs ($fp, "Content-type: application/x-www-form-urlencoded\n");
		$out = "";
		while (list ($k, $v) = each ($data))
			{
			//echo "Posting $k (" . htmlspecialchars ($v) . ")";
			if(strlen($out) != 0) $out .= "&";
			$out .= rawurlencode($k). "=" .rawurlencode($v);
			}
		$out = trim ($out);
		fputs ($fp, "Content-length: ".strlen($out)."\n\n");
		fputs ($fp, "$out");
		fputs ($fp, "\n");
		while(!feof($fp))
			{
			$ret .= fgets($fp,128);
			}
		fclose ($fp);
		} else {
			//echo "No FP";
		}
	return $ret;
}

function post_send_headers ($fp) {
	fputs ($fp, "Accept: */*\n");
	fputs ($fp, "Accept-Language: en\n");
	fputs ($fp, "Connection: Keep-Alive\n");
	fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows
98)\n");
}



-- 
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Maris Kalnins
Gwyn Morfey

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved