# Memory streams

- Thread: https://externals.io/message/30890
- Original archive: https://news-web.php.net/php.internals/30890
- Started by Adrian Drumea on 2007-07-13T13:02:40+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #30890 — Adrian Drumea — 2007-07-13T13:02:40+00:00

URL: https://externals.io/message/30890#30890

Hello,

I'm new to this list, so I aplogize if this is not the place to 
post this message.

I was using today the `getimagesize()` function which takes a file 
name. I was trying to take the size of an image decoded using
base64_decode from a string. So I have my decoded data in $data.
Now to apply `getimagesize()` I need a file, so I saved $data to 
a temporary file and everything worked. I then tried to avoid
the temporary file by using i/o streams, but I didn't manage to 
do this. 

Correct me if I am wrong, but from what I see there is no way
to create a memory stream using php://memory and also attach
a unique key to it. If that would be possible, I could create 
a memory stream with a unique key, write the data into it and
then pass this memory stream name to the `getimagesize()` function.

In this way, all functions requiring a file could be used on
a memory buffer. 

Adrian Drumea

---

## #30891 — Derick Rethans — 2007-07-13T13:11:29+00:00

URL: https://externals.io/message/30890#30891 · In reply to: #30890

> I'm new to this list, so I aplogize if this is not the place to 
> post this message.

It fits the php-general list better perhaps.

> In this way, all functions requiring a file could be used on a memory 
> buffer.

You mean like this:
http://no.php.net/manual/en/wrappers.data.php ?

regards,
Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #30892 — Frode E. Moe — 2007-07-13T13:18:17+00:00

URL: https://externals.io/message/30890#30892 · In reply to: #30890

> Hello,
> 
> I'm new to this list, so I aplogize if this is not the place to 
> post this message.
> 
> I was using today the `getimagesize()` function which takes a file 
> name. I was trying to take the size of an image decoded using
> base64_decode from a string. So I have my decoded data in $data.
> Now to apply `getimagesize()` I need a file, so I saved $data to 
> a temporary file and everything worked. I then tried to avoid
> the temporary file by using i/o streams, but I didn't manage to 
> do this. 
> 
> Correct me if I am wrong, but from what I see there is no way
> to create a memory stream using php://memory and also attach
> a unique key to it. If that would be possible, I could create 
> a memory stream with a unique key, write the data into it and
> then pass this memory stream name to the `getimagesize()` function.
> 
> In this way, all functions requiring a file could be used on
> a memory buffer. 

You could implement your own stream with `stream_wrapper_register()`, and
then use URLs like "mycustomstream://12345678", and your stream
implementation could then extract the "12345678" part to use as a key,
for example.
