PHP Classes

File: test_http_image_request.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP HTTP protocol client   test_http_image_request.php   Download  
File: test_http_image_request.php
Role: Example script
Content type: text/plain
Description: Example script on how to request an image from a remote site to made available through a local server
Class: PHP HTTP protocol client
HTTP client to access Web site pages
Author: By
Last change: Fixed short open PHP tags.
Date: 9 years ago
Size: 1,276 bytes
 

Contents

Class file image Download
<?php
/*
 * test_http_image_request.php
 *
 * @(#) $Header: /opt2/ena/metal/http/test_http_image_request.php,v 1.5 2015/05/26 09:04:17 mlemos Exp $
 *
 */

   
require("http.php");

   
set_time_limit(0);
   
$http=new http_class;
   
$url="http://www.phpclasses.org/graphics/logo.gif";
   
$error=$http->GetRequestArguments($url,$arguments);
   
$error=$http->Open($arguments);
    if(
$error=="")
    {
       
$error=$http->SendRequest($arguments);
        if(
$error=="")
        {
           
$headers=array();
           
$error=$http->ReadReplyHeaders($headers);
            if(
$error=="")
            {
                for(
Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
                {
                   
$header_name=Key($headers);
                    if(
GetType($headers[$header_name])!="array")
                    {
                        switch(
strtolower($header_name))
                        {
                            case
"content-type":
                            case
"content-length":
                               
Header($header_name.": ".$headers[$header_name]);
                                break;
                        }
                    }
                }
                for(;;)
                {
                   
$error=$http->ReadReplyBody($body,1000);
                    if(
$error!=""
                   
|| strlen($body)==0)
                        break;
                    echo
$body;
                }
            }
        }
       
$http->Close();
    }
    if(
$error!="")
    {
?>
<HTML>
<HEAD>
<TITLE>Error</TITLE>
</HEAD>
<BODY>
<H1><CENTER>Could not retrieve the resource. Error: <?php echo $error; ?></CENTER><H1>
<HR>
</BODY>
</HTML>
<?php
   
}
?>