Re: [PHP] Using named Pipes between PHP and ZIP

2012-07-09 Thread Matijn Woudt
On Mon, Jul 9, 2012 at 7:19 PM, Dennis Heck  wrote:
>
> Unfortunately it makes no difference if i use zip with 2 - or if I leave
> them ommited. The longer I guess about it, the more I think it might be a
> ZIP topic, namely how the stream to stdin needs to be like so zip will know
> the name of the file from it.
>
>
> Regards,
> Dennis

This is a known problem with zip, it's just not possible. Either you
select files, or you pass something on stdin (which will have no
filename). You will have to do the same trick with mkfifo, but you can
use the php function posix_mkfifo[1] for that.

- Matijn

[1] php.net/posix_mkfifo

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



Re: [PHP] Using named Pipes between PHP and ZIP

2012-07-09 Thread Dennis Heck


Unfortunately it makes no difference if i use zip with 2 - or if I leave 
them ommited. The longer I guess about it, the more I think it might be a 
ZIP topic, namely how the stream to stdin needs to be like so zip will know 
the name of the file from it.


Regards,
Dennis 



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



Re: [PHP] Using named Pipes between PHP and ZIP

2012-07-08 Thread tamouse mailing lists
≈On Sun, Jul 8, 2012 at 11:30 AM, Dennis Heck  wrote:
> Hello everyone,
>
> I'm looking for a solution for the following:
> 1) collecting data from a simple html form and send them to a php script
> 2) take the data and place them in a php-generated excel sheet
> 3) zip the excel sheet and password protect the zip file (standard
> encription will be sufficent, no AES needed)
> 4) send the zip file as an email attachment
> This kind of output is fixed, changing the output is not an option.
>
> I'm ok with building the excel sheet and sending the mail, but I'm still
> trying and error with the zip. Since I need password protection in the zip,
> I cannot use the php build in zip extension. I guess I will need to call ZIP
> on the shell. I'm aware I could first save the generated excel sheet to the
> filesystem and afterwards call the zip process on the file, putting the zip
> file also to the file system. But I wonder if there's an option to stream
> the data till they finally can be put to the multipart mail - without saving
> anything to the filesystem.
>
> Here is my first try, just a little modification of the example on proc_open
> in the php docu. To keep the test simple, I load a sample xls from the
> filesystem instead of generating from the php class and output it directly
> to the browser. The script works well except one point: the file contained
> in the zip will have no name an no file extension.
>
>header ('Content-type: application/zip');
>header ('Content-Disposition: attachment; filename="download.zip"');
>
>$descriptorspec = array(
>0 => array("pipe", "r"),
>   1 => array("pipe", "w"),
>   2 => array("file", "error-output.txt", "a")
>);
>
>$dateiname = 'xyz.xls';
>$file = fread(fopen($dateiname, "r"), filesize($dateiname));
>
>$process = proc_open('zip -P 1234', $descriptorspec, $pipes);
>
>if (is_resource($process)) {
>
>fwrite($pipes[0], $file);
>fclose($pipes[0]);
>
>$zip = stream_get_contents($pipes[1]);
>fclose($pipes[1]);
>
>$return_value = proc_close($process);
>}
>
>echo $zip;
>?>
>
> So I look for an option to get the name and extension in the zipfile. Here I
> found named pipes as an option. Calling via shell, tested with a textfile in
> order to use less
>
>mkfifo xyz.txt
>less readme.txt > xyz.txt & zip output.zip -FI xyz.txt -P 1234
>rm xyz.txt
>
> Now I get a pw protected zip file containing xyz.txt. Now how can I combine
> both? How can I tell php to use the named pipe instead of stdin in
> proc_open? Or any other idea to get the file in the zip the correct name and
> extension.
>
> Thanks in advance,
> Regards,
> Dennis
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

I *think* all you need in the first paramter to proc_open is :

zip -P password - -

The first - is the zip file -- which will be send to stdout.
The second - is the input -- which you should pipe your spreadsheet into.

Good luck!

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