I'm trying to read from the php://memory
wrapper using fread()
but fread()
always returns false. My code is simplified:
$file_handle = fopen('php://memory', 'w+'); // Have tried php:temp also.
fwrite($file_handle, 'contents');
$file = fread($file_handle, filesize($file_handle)); // Have also tried 99999 for filesize.
$file
always is false after the fread()
.
What's going on?
Thanks in advance!
You'll need to rewind($file_handle) after writing before you can read what you've just written, because writing moves the file pointer to the end of the file
Call rewind($file_handle)
before fread()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With