Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.php > #3273 > unrolled thread

Get root directory in archive

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2021-07-02 12:14 +1000
Last post2021-07-03 15:58 +1000
Articles 3 — 2 participants

Back to article view | Back to alt.php


Contents

  Get root directory in archive Andrew Poulos <ap_prog@hotmail.com> - 2021-07-02 12:14 +1000
    Re: Get root directory in archive "J.O. Aho" <user@example.net> - 2021-07-02 09:07 +0200
      Re: Get root directory in archive Andrew Poulos <ap_prog@hotmail.com> - 2021-07-03 15:58 +1000

#3273 — Get root directory in archive

FromAndrew Poulos <ap_prog@hotmail.com>
Date2021-07-02 12:14 +1000
SubjectGet root directory in archive
Message-ID<iL6dnfbxRIzl60P9nZ2dnUU7-N3NnZ2d@westnet.com.au>
Users can upload a archive (zip) to the server. On the server I can use 
extractTo to extract the archive's contents.

The problem I have is that users should create an archive of an entire 
directory and not just the directory's contents (so that when the 
archive is extracted the contents will be in a directory.)

How can I test whether all the files, and any sub-directories within an 
archive, are within one directory?

If they are within one directory I would also like the directory's name.

Andrew Poulos

PS I'm a PHP noob

[toc] | [next] | [standalone]


#3274

From"J.O. Aho" <user@example.net>
Date2021-07-02 09:07 +0200
Message-ID<ik7s8uFpbqdU1@mid.individual.net>
In reply to#3273
On 02/07/2021 04.14, Andrew Poulos wrote:
> Users can upload a archive (zip) to the server. On the server I can use 
> extractTo to extract the archive's contents.
> 
> The problem I have is that users should create an archive of an entire 
> directory and not just the directory's contents (so that when the 
> archive is extracted the contents will be in a directory.)
> 
> How can I test whether all the files, and any sub-directories within an 
> archive, are within one directory?

You will need to use the getNameIndex to list the files
https://www.php.net/manual/en/ziparchive.getnameindex.php

> If they are within one directory I would also like the directory's name.

you would use dirname to figure out the path, you can use the level to 
get the root.
https://www.php.net/manual/en/function.dirname.php

You can store the first files root directory in a variable, then check 
if the next file has the same root as the previous one, if they differ, 
than you know there is multiple directories. If the variable value is 
empty, then you have files directly in the root.

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#3282

FromAndrew Poulos <ap_prog@hotmail.com>
Date2021-07-03 15:58 +1000
Message-ID<q8idnY8dh6ToYUL9nZ2dnUU7-K-dnZ2d@westnet.com.au>
In reply to#3274
On 2/07/2021 5:07 pm, J.O. Aho wrote:
> 
> On 02/07/2021 04.14, Andrew Poulos wrote:
>> Users can upload a archive (zip) to the server. On the server I can 
>> use extractTo to extract the archive's contents.
>>
>> The problem I have is that users should create an archive of an entire 
>> directory and not just the directory's contents (so that when the 
>> archive is extracted the contents will be in a directory.)
>>
>> How can I test whether all the files, and any sub-directories within 
>> an archive, are within one directory?
> 
> You will need to use the getNameIndex to list the files
> https://www.php.net/manual/en/ziparchive.getnameindex.php
> 
>> If they are within one directory I would also like the directory's name.
> 
> you would use dirname to figure out the path, you can use the level to 
> get the root.
> https://www.php.net/manual/en/function.dirname.php
> 
> You can store the first files root directory in a variable, then check 
> if the next file has the same root as the previous one, if they differ, 
> than you know there is multiple directories. If the variable value is 
> empty, then you have files directly in the root.

Yep, that did it. Thanks.

Andrew Poulos

[toc] | [prev] | [standalone]


Back to top | Article view | alt.php


csiph-web