# playing with files

**URL:** <https://www.phphelp.com/t/playing-with-files/19371>\
**Category:** General PHP Help\
**Created:** [January 17, 2013, 5:54am UTC](https://www.phphelp.com/t/playing-with-files/19371 "2013-01-17T05:54:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [January 17, 2013, 5:54am UTC](https://www.phphelp.com/t/playing-with-files/19371/1 "2013-01-17T05:54:18Z")

</div>

Not the best description, i know, but i need some help here 🙂

I have a script that pulls out attachments, unzips gz files, which is fine, but it also pulls out regular zip archives. I figured out how to unzip those, my problem is the contents of the zip. it contains 4 files, all with different names (below)

spotify-revshare-for-downloads-for-venzodigital-201211.txt  
spotify-revshare-for-venzodigital-201211.txt  
spotify-track-for-downloads-for-venzodigital-201211.txt  
spotify-track-for-venzodigital-201211.txt

The only file i have to import is the last one (also happens to be the largest in size).

Is there some way that i can just extract that one file and then delete the entire archive? I have a feeling i’ll have to extract all the files into a folder, then check the size on each one, then delete the ones i don’t want, then move that one file back into another folder for to be imported.

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 17, 2013, 6:24am UTC](https://www.phphelp.com/t/playing-with-files/19371/2 "2013-01-17T06:24:38Z")

</div>

> [@richei](#):
>
> I have a feeling i’ll have to extract all the files into a folder, then check the size on each one, then delete the ones i don’t want

I think this is pretty accurate. I’m no sysadmin but I have never seen a way to extract a file based on it’s size.

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [January 17, 2013, 6:26am UTC](https://www.phphelp.com/t/playing-with-files/19371/3 "2013-01-17T06:26:56Z")

</div>

yea i was just hoping there was a simpler way of doing it. oh well, time to add another 50 or so lines of code ☹

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 17, 2013, 8:28pm UTC](https://www.phphelp.com/t/playing-with-files/19371/4 "2013-01-17T20:28:13Z")

</div>

This could be useful, if you could check the uncompressed size of all files in a zip you could then extract only the largest file.

> **[Unix and Linux Forums](https://www.unix.com/man-page/linux/1/gzip/)**
>
> UNIX and Linux shell scripting, admin and programming help. Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here for free answers.

-l --list

For each compressed file, list the following fields:

compressed size: size of the compressed file  
uncompressed size: size of the uncompressed file  
ratio: compression ratio (0.0% if unknown)  
uncompressed\_name: name of the uncompressed file

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [January 18, 2013, 4:21pm UTC](https://www.phphelp.com/t/playing-with-files/19371/5 "2013-01-18T16:21:26Z")

</div>

That’s if you were using a shell script, it would just display it on the screen. I’ve got a good idea on how to do it with php.

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 18, 2013, 7:17pm UTC](https://www.phphelp.com/t/playing-with-files/19371/6 "2013-01-18T19:17:40Z")

</div>

I was thinking you could use shell\_exec() which would send the gzip -l results to a string that you could parse to find the largest file.

---

<div class="post-metadata">

**Author:** ![richei](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@richei](https://www.phphelp.com/u/richei)\
**Post date:** [January 18, 2013, 7:58pm UTC](https://www.phphelp.com/t/playing-with-files/19371/7 "2013-01-18T19:58:33Z")

</div>

Php has built in functions for zip files and I havent had any luck in the past in using shell shell functions in a cronjob… Im going be working on it tonight. Ill post what I have if I get it figured out.
