Login   Register  
PHP Classes
elePHPant
Icontem

File: test_http_image_request.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: Synchronized with CVS version
Date: 3 years ago
Size: 1,273 bytes
 

Contents

Class file image Download
<?php
/*
 * test_http_image_request.php
 *
 * @(#) $Header: /opt2/ena/metal/http/test_http_image_request.php,v 1.4 2003/10/28 22:09:35 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: <? echo $error?></CENTER><H1>
<HR>
</BODY>
</HTML>
<?php
    
}
?>