I'm creating a gzipped file and trying to read it into an attachment. In trying to streamline the process I've run into something that doesn't work.
This works:
$tempfile = /directory/filename.txt.gz;
$pointer = gzopen($tempfile, 'w9');
gzwrite($pointer, "some text");
gzclose($pointer);
$file = fopen($tempfile,'rb');
$data = fread($file,filesize($tempfile));
fclose($file);
(at which point I base64 encode $data into an attachment)
This doesn't work:
$tempfile = /directory/filename.txt.gz;
$pointer = gzopen($tempfile, 'w9');
gzwrite($pointer, "some text");
$data = fread($pointer,filesize($tempfile));
gzclose($pointer);
(at which point I base64 encode $data into an attachment)
In other words, what I'm trying to do is read the gz-encoded file from memory, instead of writing to disk, closing, then opening a non-gz file, reading the gz file into it (retaining the gz encoding, since I'm not gzread-ing it), and closing that file.
Can I do this?