Manuel PHP
Précédent |  | Suivant

# file_register_wrapper

(PHP 4 CVS only)

file_register_wrapper -- Register a URL wrapper implemented as a PHP class

## Description

boolean file_register_wrapper ( string protocol, string classname)

This function is currently only documented by the example below:

Exemple 1. Implementing a base64 encoding protocol
    class Base64EncodingStream {
        var $fp = null;

        function stream_open($path, $mode, $options, &$opened_path)
        {
            $this->fp = fopen($path, $mode);
            return is_resource($this->fp);
        }
        function stream_close()
        {
            fclose($this->fp);
        }
        function stream_read($count)
        {
            return false; // We only allow writing
        }
        function stream_write($data)
        {
            return fwrite($this->fp, base64_encode($data));
        }
        function stream_flush()
        {
            fflush($this->fp);
            return true;
        }
        function stream_seek($offset, $whence)
        {
            return false;
        }
        function stream_gets()
        {
            return false;
        }
        function stream_tell()
        {
            return false;
        }
        function stream_eof()
        {
            return false;
        }
    }
    file_register_wrapper("base64", "Base64EncodingStream")
        or die("Failed to register protocol");

    copy("/tmp/inputfile.txt", "base64:///tmp/outputfile.txt");
    readfile("/tmp/outputfile");

file_register_wrapper() will return false if the `protocol` already has a handler, or if "fopen wrappers" are disabled.

> Note : This function was introduced in PHP 4.3.0.

Précédent | Sommaire | Suivant
file_get_wrapper_data | Niveau supérieur | file