Return to Snippet

Revision: 83
at July 5, 2006 13:20 by neogeek


Updated Code
if (!function_exists('fetch_remote_file')) {

   function fetch_remote_file($file) {

      $path = parse_url($file);

      $fs = @fsockopen($path['host'], 80);

      if ($fs) {

         $header  = 'GET ' . $file . ' HTTP/1.0' . lnbr;
         $header .= 'Host: ' . $path['host'] . str_repeat(lnbr, 2);

         fwrite($fs, $header);

         $buffer = '';

         while ($tmp = fread($fs, 1024)) { $buffer .= $tmp; }

         $matches = Array();

         preg_match('/Content-Length: ([0-9]+)/', $buffer, $matches);

         return substr($buffer, [email protected]$matches[1]);

      } else { return false; }

   }

}

Revision: 82
at July 5, 2006 13:18 by neogeek


Updated Code
if (!function_exists('fetch_remote_file')) {

   function fetch_remote_file($file) {

      $path = parse_url($file);

      $fs = @fsockopen($path['host'], 80);

      if ($fs) {

         $header  = 'GET ' . $file . ' HTTP/1.0' . lnbr;
         $header .= 'Host: ' . $path['host'] . str_repeat(lnbr, 2);

         fwrite($fs, $header);

         $buffer = '';

         while ($tmp = fread($fs, 1024)) { $buffer .= $tmp; }

         $matches = Array();

         preg_match('/Content-Length: ([0-9]+)/', $buffer, $matches);

         return substr($buffer, -$matches[1]);

      } else { return false; }

   }

}

Revision: 81
at June 29, 2006 22:26 by neogeek


Initial Code
if (!function_exists('fetch_remote_file')) {

   function fetch_remote_file($file) {

      $path = parse_url($file);

      $fs = @fsockopen($path['host'], 80);

      if ($fs) {

         $header  = 'GET ' . $path['path'] . ' HTTP/1.0' . lnbr;
         $header .= 'Host: ' . $path['host'] . str_repeat(lnbr, 2);

         fwrite($fs, $header);

         $buffer = '';

         while ($tmp = fread($fs, 1024)) { $buffer .= $tmp; }

         $matches = Array();

         preg_match('/Content-Length: ([0-9]+)/', $buffer, $matches);

         return substr($buffer, -$matches[1]);

      } else { return false; }

   }

}

Initial URL

 

Initial Description
This simple function allows you to fetch files from other web sites in PHP4 without needing to install any extensions for PHP.

Initial Title
Fetch Remote File

Initial Tags
file

Initial Language
PHP