/**
* net-get-RemoteFile()
*
* Returns a remote fle.
* @param string $path - path to the remote file.
* @param string $method -method to use," get="" or="" post="">
* @param int $timeout - seconds before timeout, defaults to 30.
* @return string.
*/
function net_get_remoteFile($path,$method='GET',$timeout=30){
$parts = parse_url($path);
$params = isset($parts['query'])?$parts['query']:'';
$fp = fsockopen(isset($parts['host'])?$parts['host']:$parts['path'], 80, $errno, $errstr,$timeout);
if (!$fp) {
echo "$errstr ($errno)\n";
}
else {
$out = strtoupper($method). " " . $parts['path'] . " HTTP/1.1\r\n";
$out .= "Accept: */*\n";
$out .= "Host: " . $parts['host'] . "\r\n";
if(strtoupper($method) == "POST" ) {
$strlength = strlen($params);
$out .= "Content-type: application/x-www-form-urlencoded\n";
$out .= "Content-length: ".$strlength."\n\n";
$out .= $params."\n";
}
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$contents = '';
while (!feof($fp)) {
$contents .= fgets($fp, 1024);
}
fclose($fp);
}
return $contents;
}
PHP and javascript snippets you can copy and paste.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(71)
-
▼
March
(25)
- net_get_HTMLDescriptionFromCode($HTMLCode)
- net_increment_ipAddress($iPAddress)
- sec_remove_emailInjectionChars($str)
- str_get_textBetween($start,$end,$str)
- str_remove_doubleQuotes($str)
- str_remove_Quotes($str)
- ajax request
- str_remove_singleQuotes($str)
- str_explode_strAssoc($separator,$assignSeparator,$...
- str_get_strlenmb($s)
- str_get_substrmb($s,$start,$len)
- ajx_print_r
- str_remove_strFromStart($needle,$haystack)
- file_write($fileName, $data, $mode)
- net_get_remoteFile($path,$method='GET',$timeout=30)
- str_get_pointsBetween($start,$end,$s,$n=0)
- dir_do_dirIteratorCallback($dir,$fn,$params)
- fnc_conv_argsToArray()
- net_conv_urlStringToArray($urlStr)
- net_conv_arrayToURLStr($arr,$prefix,$arg_separator)
- xml_get_isXML($xml)
- str_get_strMatchesEnd($needle,$haystack)
- str_conv_strToLowerCaseArray($separator,$s)
- fnc_wrap($fnc)
- net-get-randomIP()
-
▼
March
(25)
No comments:
Post a Comment