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"); |