note 76669 deleted from function.stream-copy-to-stream by cmb

From: Date: Thu, 25 Aug 2016 00:31:05 +0000
Subject: note 76669 deleted from function.stream-copy-to-stream by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206384@lists.php.net to get a copy of this message
Note Submitter: sundance2001 guess what gmail.com ---- 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; }

« previous php.notes (#206384) next »