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

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

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.

 

16 Responses

  1. Woody says:

    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.

    • Abdul Awal says:

      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

  2. payal says:

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

    Why…??

  3. jess says:

    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!

  4. jess says:

    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!

  5. Anna Brown says:

    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?

  6. ts says:

    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?

  7. VF says:

    Great Work

  8. ryan says:

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

  9. Waqas says:

    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.

  10. navas says:

    Great Work ,Thank you Abdul Awal

  11. 1stbootstrap says:

    Many Many thanks for great script.

  12. lolzic says:

    nothing happens to me

  13. Sam Hans says:

    thank u so much 🙂 May Allah bless u

Leave a Reply

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