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

Abdul AwalArticles, Web Development11 Comments

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.

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

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 AwalCreate Zip file with content of current Directory with php – ZipCF

11 Comments on “Create Zip file with content of current Directory with php – ZipCF”

  1. Pingback: Zip and Unzip files with FTP client/Filezilla | Abdul Awal Uzzal

  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

  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!

  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!

  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. ts

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *