note 76669 added to function.stream-copy-to-stream
| From: | sundance2001guesswhatgmail dot com at osu1 dot php dot net | Date: | Wed, 25 Jul 2007 13:54:53 +0000 |
| Subject: | note 76669 added to function.stream-copy-to-stream | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128916@lists.php.net to get a copy of this message | ||
If you need to copy a file from any website into yours you can use following function:
function getUrlContents($url)
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
if ($url == '' || $host == '') {
return false;
}
$port = 80;
$path = (empty($url_parsed["path"]) ? '/' : $url_parsed["path"]);
$path.= (!empty($url_parsed["query"]) ? '?'.$url_parsed["query"] :
'');
$out = "GET $path HTTP/1.0\r\nHost: $host\r\nConnection: Close\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$headers = '';
$content = '';
$buf = '';
$isBody = false;
while (!feof($fp) and !$isBody) {
$buf = fgets($fp, 1024);
if ($buf == "\r\n" ) {$isBody = true;}
else{$headers .= $buf;}
}
$file1 = fopen(basename($url_parsed["path"]), 'w');
$bytes=stream_copy_to_stream($fp,$file1);
fclose($fp);
return $bytes;
}
----
Server IP: 195.54.192.44
Probable Submitter: 85.113.130.160
----
Manual Page -- http://www.php.net/manual/en/function.stream-copy-to-stream.php
Edit -- https://master.php.net/note/edit/76669
Del: integrated -- https://master.php.net/note/delete/76669/integrated
Del: useless -- https://master.php.net/note/delete/76669/useless
Del: bad code -- https://master.php.net/note/delete/76669/bad+code
Del: spam -- https://master.php.net/note/delete/76669/spam
Del: non-english -- https://master.php.net/note/delete/76669/non-english
Del: in docs -- https://master.php.net/note/delete/76669/in+docs
Del: other reasons-- https://master.php.net/note/delete/76669
Reject -- https://master.php.net/note/reject/76669
Search -- https://master.php.net/manage/user-notes.php