Re: Re: meaning or 'flags' in ZipArchive->open() ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Apr 9, 2015, at 4:15 PM, Maciek Sokolewicz wrote:



On 10 April 2015 at 00:59, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:
>
>
> On Apr 9, 2015, at 3:41 PM, Maciek Sokolewicz wrote:
>
>> On 9-4-2015 21:48, Jeffry Killen wrote:
>>>
>>> Hello;
>>>
>>> Is there a reference to explanations of the meanings of the
>>> flags here I have marked with ??:
>>> ZIPARCHIVE::OVERWRITE (I presume this means to remove existing content
>>> and start fresh)
>>> ZIPARCHIVE::CREATE
>>>
>>> ZIPARCHIVE::EXCL ?? (EXCL == exclude(?))
>>>
>>> ZIPARCHIVE::CHECKCONS ??
>>>
>>> There is no explanation in my copy of the manual
>>>
>>> accept what is obvious in the examples given.
>>>
>>> Thanks
>>>
>>> JK
>>
>>
>> Read the only up-to-date version of the manual: http://www.php.net/manual/en/zip.constants.php
>> (and yes, they're class constants)
>>
>> - Tul
>>
>
> Thank you; very helpful.
>
> It would be nice if there was a full manual on using this alone. I could google using zip compression or something similar.
>
> So; as I understand it a constant will have an integer associated
> and might be used in a lookup array to get the string value?
>
> I will play around with this to get a feel for it.
>
> Thanks for time and attention
> JK
>

Please reply to the list as well.

The manual actually fully explains how to use them. It states that you need to supply one of the flags in various functions/methods to get some desired effect.

For instance:
http://www.php.net/manual/en/ziparchive.open.php

When using ZipArchive::open() it requires up to 2 parameters:
a filename, and an optional flag, which may be one of the following constants: ZipArchive::OVERWRITE, ZipArchive::CREATE, ZipArchive::EXCL or ZipArchive::CHECKCONS. Each constant has an integer value. What this value is exactly, you shouldn't care. Internally, the method wants to receive an integer; but for you (the developer), it's much easier to figure out what's going on by using a clear name; so instead you use a constant.

So when the following is used:
$filename = './archive.zip';
ZipArchive::open($filename, ZipArchive::CREATE);

PHP translates it to:
ZipArchive::open('./archive.zip', 1); // since the value of ZipArchive::CREATE is some number, for example 1 (I don't know for sure what it is, this is just for example purposes)

good guess... it is 1 according to my probing.


Now, you could of course just write things like:
ZipArchive::open('./archive.zip', 1);
ZipArchive::open('./archive.zip', 3);

but do you now immediately know what's going on here? And what each flag does? Of course not. So instead we use constants which have a clear name that tells us what the flag means, and have the corresponding value (integer):
ZipArchive::open('./archive.zip', ZipArchive::CREATE);
ZipArchive::open('./archive.zip', ZipArchive::OVERWRITE);

The manual itself shows you a ton of examples: http://www.php.net/manual/en/zip.examples.php and the entire ZipArchive chapter (http://www.php.net/manual/en/book.zip.php ) also contains a ton of info. No need to google anything, just RTFM (online!).

- Tul

OK:
I thank you for pointers on where to find info in the manual on line. I have trouble navigating the manual to find these things myself. What I was wondering about most is the ZipArchive::CM... constants, Where are they important and how would one use them? for instance there is a ZipArchive constant CM_BZIP2: where and how would I specify this algorythm?
And as well; comments, index, and name: What do these apply to?
Or suppose I wanted to remove an element from a zip archive file without overwriting the whole thing? Is that possible? How would I do that? I am thinking along the lines of an O'Reilly or Apress text on the subject. That is what I would google for.

I am in the process of compiling look up arrays to associate a string with each of the constant values I came across two oddities: mind you the version I am using is php v5.3.26

//ZipArchive::CM_REDUCE_4: also shows 5
$_constCM[5] = 'ZipArchive::CM_REDUCE_3: reduced with factor 3';

-1 won't fit into an indexed array:
// ZipArchive::CM_DEFAULT gives -1: better of deflate or store
$_constCM_DEF = array(); // CM ??
$_constCM_DEF['code'] = -1;
$_constCM_DEF['means'] = "better of deflate or store";

I have just begun the ER constants.

Additionally, this is the first time I have payed any attention to the inner workings of compression software.

As always thanks for time and attention:
JK



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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux