On 9 February 2010 16:47, Ryan Sun <ryansu...@gmail.com> wrote:
> thanks, Richard, maybe you are right, the actual file name is not my job
> I changed it to 'php://temp' but its still the same, nothing has been 
> changed...
>
> On Tue, Feb 9, 2010 at 11:13 AM, Richard Quadling
> <rquadl...@googlemail.com> wrote:
>> On 9 February 2010 15:42, Ryan Sun <ryansu...@gmail.com> wrote:
>>> I want to generate credential zip file for user on the fly with
>>> zipArchive and render it for download, so I created following code
>>> ---------------------------------------------------------
>>> $zip = new ZipArchive();
>>> $filename = '/tmp/xxx.zip';
>>> if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
>>>      throw new Exception();
>>> }
>>> if($zip)
>>> {
>>>     $zip->addFromString('xxx.xx', $fileString);
>>> }
>>> $zip->close();
>>> $fileString = file_get_contents($filename);
>>> unlink($filename);
>>>
>>> $this->getResponse()->setHeader('Content-Type', 'application/zip');
>>> $this->getResponse()->setHeader('Content-Disposition','attachment;filename=xxx.zip');
>>> $this->getResponse()->setBody($fileString);
>>> -----------------------------------------------------
>>> it works, but I think creating the file in memory is a better
>>> approach, so I changed the 2nd lineI(using php 5.2.0) to
>>> $filename = 'php://temp/xxx.zip';
>>> then the php just won't archive the file and the file downloaded is
>>> just a plain text file.
>>>
>>> so
>>> question 1, how to create zip Archive file in memory on the fly and
>>> download it (I don't have to save it on disk)?
>>> question 2, if there is no way to create in memory, is it safe to just
>>> unlink() the file?
>>>
>>> thanks in advance.
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>> According to http://docs.php.net/manual/en/wrappers.php.php, it looks
>> like you should be using ...
>>
>> $filename = 'php://temp';
>>
>> That's it.
>>
>> The actual file name is not your job.
>>
>>
>>
>> --
>> -----
>> Richard Quadling
>> "Standing on the shoulders of some very clever giants!"
>> EE : http://www.experts-exchange.com/M_248814.html
>> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>

It looks like this isn't possible.





-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to