,

Create Zip file with content of current Directory with php – ZipCF

Create a zip of the current directory with PHP

A few days ago I’ve shared a php script to unzip files. After that I received a few queries for a different script that will create zip files with content of current directory. And that’s why I am writing this article today.

Today, I’m going to share a php script that will create zip file using content of current directory. Its a very simple script and the workflow is simple as well!

Let’s know about how it works:

If you run the script it will find all the files, folders inside the folder (where you placed the script) and create a zip file inside this folder with all the files and folders.

With version 2.0, you can now select the files and folders you want to include in zip file. 

Here’s a video that explains features and way to use:

How to use ?

  • Simply click here to get the script
  • Upload zipCF.php on the directory which you want to make zip file
  • Open zipCF.php with your browser
  • Provide a Name for the zip file
  • Click on Create Zip file
  • It will create the zip file if everything is ok and provide a success message just below the submit button
  • If you see the success message, go to ftp client or browse direct url to zip file from your browser
  • Download the newly created zip file
  • Use it anyhow you need
  • Delete zipCF.php file from your server to avoid security issues

ZipCF - PHP based zip creation script - Create zip files even if you only have ftp login to server. | Product Hunt Embed

Questions/Comments ?

Please feel free to leave your comment using the comment box below.

Credits

Thanks to David Walsh for his very useful article which I’ve used to create this script.

Abdul Awal Uzzal
Written byAbdul Awal Uzzal

Tech entrepreneur and AI-first founder. I lead the team behind ThemeNcode, TNCFlow and TNC FlipBook.

Get in touch

48 responses to “Create Zip file with content of current Directory with php – ZipCF”

  1. […] How to Zip/Compress Files using Filezilla ? […]

    1. Alkar

      Thanks for sharing this solution and script. πŸ™‚

  2. Woody

    Nice script! Thank you for sharing.

    Couple of questions please:

    1) Is there a way to set the directory wishing to ZIP? Lets say I have zipCF in one directory and wish to zip directory above (ie: ../).

    2) Is there a way to add directories to exclude from zip? I have a few directories that I wish to exclude (ie: data, temp)

    Thanks again for sharing.

    1. Abdul Awal

      Hi Woody,
      Thanks for your comment.
      1. In current version of zipCF, There’s no option to select a directory. I’ll release an updated version soon & that version will have this option.

      2. No such option available with the script.

      Thanks again

      1. Julian Sloman

        Is it soon yet?

    2. Hi when i open this file with browser it open like a html code?

      1. Heyy Abdul!
        Same problem here. No idea, how to run that .php file on any browser (i copied it to a remote host directory via ftp). What requirements / dependencies it has in order to get to the login screen ..instead of displaying the folder structure and/or .php script? Thanks for any help man! Best wishes!

  3. payal

    Hi
    Its Shows me below mention Error
    “503 Service Unavailable
    No server is available to handle this request. ”

    Why…??

  4. jess

    Hi, nice and useful script
    it doesn’t work here, I got this message:
    Warning: ZipArchive::close(): Read error: Is a directory in /htdocs/public/www/myweb.com/wp-content/uploads/2013/zipCF.php on line 105
    Failed to create zip file, Please try again

    Any solution to this?
    Thanks!

    1. Abdul Awal

      Please check the latest version (1.1). It should work now.

      Thank You

      1. Where is the link to download this new version

  5. jess

    Hi again,
    The mentioned error appears to be related to the php version, in v5.6 the script doesn’t works.
    But with v5.4.4 works fine!

    Thanks!

    1. Abdul Awal

      Hi Jess,
      Thanks for pointing this. I’ll check it to understand what’s going wrong.

  6. Anna Brown

    I uploaded the php file to the directory I wanted to zip but Im getting a 500 error. I can navigate to other files in that directory with my browser but not yours? Any idea?

  7. It doesn’t work here, I got this message:
    Warning: ZipArchive::close(): Read error: Is a directory in /home/td/.xxxxx.com/_backup/_oldrpclone/zipCF.php on line 105
    Failed to create zip file, Please try again

    Any solution to this?

    1. To help you (and me !) , I have same problem, but it work with Folder with not a lot of files.
      I’m looking for a solution.

    2. Abdul Awal

      Please check the latest version (1.1). It should work now.

      Thank You

  8. VF

    Great Work

  9. ryan

    Notice: Undefined offset: 1 in /var/www/fica/public_html/zipCF.php on line 120

    1. Hugo

      Same error here πŸ™

  10. Waqas

    Hi,

    I am facing following error. Can you please guide me – how to resolve?

    ‘Failed to create zip file, Please try again ‘

    Thanks in advance.

    1. Abdul Awal

      Please check the latest version (1.1). It should work now.

      Thank You

    2. satya sankar

      hello, looks like, you have permission issue of your directory, I had same issue, I made 777 , now its working.

  11. navas

    Great Work ,Thank you Abdul Awal

  12. Many Many thanks for great script.

  13. Nupur Ahuja

    Failed to create zip file

    1. Abdul Awal

      Please check the latest version (1.1) & let me know if its working.

      Thank You

  14. Awesome script! Thanks for sharing! I also checked out the “unzip” script that you shared, love it! See here: https://abdulawal.com/how-to-extract-zip-files-easily-on-web-server/

  15. Ritesh Kumar Sinha

    Hello , your script was very helpful . thank you ..

  16. Looks nice except I get “Failed to create zip file, Please try again”
    so it doesnt seem to work
    have v 1.1
    any thoughts?

  17. mac

    It would be great, but it doesn’t add the empty folders to the zip file.

  18. aat

    Open zipCF.php with your browser , how to run it on the browser :-)…

  19. Chris

    good day,
    Please i tried using this script version 1.1 on my local environment Ampps and it seems not to be working, please help…
    Chris….

  20. david

    Awesome! I used in Chrome and I zipped more than 2Gb (15K files).
    Thank you for sharing!

  21. Guillaume

    Hello,

    In my use case, I’d only want to zip some of the files and directories stored in the main directory.
    Would you be willing to update your script to, say, read from a text file this list of files and directories?
    eg.:
    /zipCF.php
    /zipCF-list.txt
    /included-dir/
    /excluded-dir/
    /included-file.php
    /excluded-file.php
    and zipCF-list.txt containing
    included-dir
    included-file.php

    Or provide the same functionality any other practical way?

    Thank you.

  22. […] been a while since I started zipCF project in 2016. Many people used to visit the articles everyday which makes it obvious that the script became a little famous πŸ˜‰ That’s […]

  23. Ankush Satija

    I am using your 2.0 script for download the zip but getting error failed to create zip can you please let me know what is issue over there.

    Can you please share me latest version script.

  24. Norbert

    Very useful thanks

  25. Anonymous

    0.5

  26. Hermann

    Hi Abdul,
    Great idea and Nice script!
    Thank you for sharing your code, it solve an old problem.

  27. Anonymous

    5

  28. Anonymous

    4.5

  29. When i set a password to my file it shows a blank page nothing else. otherwise it is running perfectly what should i do ?

    1. Oldman jr.

      After the address to the file you should type ‘?password=yourpassword’ . For example: https://mywebsite.com/wp-content/plugins/ZipCF.php?password=123456

  30. Semih

    I couldn’t back up my website because I ran out of space on my server which is misconfigured by me. Probably you know the answer, dev/sda1 was seems full and i still couldn’t figure it out what the hell am i suppossed to do. That’s why Duplicator and alternatives getting stuck at the limits. Fortunately, thanks to your script, I was able to back up my entire site and download it to my computer in 10 minutes. I am still newbie this managing a VPS thing and want to thank you for your great solution. Have a nice day and keep up the good work. Best wishes from Turkey.

  31. oldman jr.

    It works like a charm. It saved my life (or at least my work) many times. Thank you very muchas gracias!

  32. Thank You Abdul, it works fine for me. Robert

  33. Nikiforos

    You must be really crazy creating that script for free. On the other hand, it is not always about money but it feels much better when helping others. So, congrats, you are a great person firstly and a brilliant developer secondly. Thank you for sharing this great script.