Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:36:26+00:00 2026-05-18T20:36:26+00:00

Currently FTP is insanely slow on our server when it comes to multiple small

  • 0

Currently FTP is insanely slow on our server when it comes to multiple small files.

I am wanting to create a file that I can run in my browser that creates a zip file.

Basically this file will sit in /htdocs

The zip file it creates must take all files in /htdocss (and sub folders ect) and mimic the structure.

Can anyone point me in the right direction?

I am attempting to use the below code.

The only issue is that,
I am getting some blank folders

say the file is:

C:/xampp/htdocs/booking/zip.php

I get
/C
/C/xampp
/C/xampp/htdocs
/C/xampp/htdocs/booking
/C/xampp/htdocs/booking/image.png
/C/xampp/htdocs/booking/index.php

I dont want /C/xampp/htdocs/booking

I just want the zip file to contain
image.png
index.php

How can I fix this?

<?php

function Zip($source, $destination) {
  if(extension_loaded('zip') === true) {
    if(file_exists($source) === true) {
      $zip = new ZipArchive();

      if($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
        $source = realpath($source);

        if(is_dir($source) === true) {
          $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

          foreach($files as $file) {
            $file = realpath($file);

            if(is_dir($file) === true) {
              $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            } else if(is_file($file) === true) {
              $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
          }
        } else if(is_file($source) === true) {
          $zip->addFromString(basename($source), file_get_contents($source));
        }
      }

      return $zip->close();
    }
  }

  return false;
}

Zip(dirname(__FILE__), 'testzip.zip');
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:36:27+00:00Added an answer on May 18, 2026 at 8:36 pm

    There are two options. You can use PHPs built-in ZipArchive and manually iterate over the directory contents (readdir or DirectoryIterator).

    Or you can do the lazy thing:

    header("Content-Type: archive/zip");   // mime 2.0
    header("Content-Disposition: attachment; filename=dir.zip");
    passthru("zip -q -r - .");
    

    Depends on the installed zip tool. It complains if you try that on the terminal, but should work over the passthru pipe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently FTP is insanely slow on our server when it comes to multiple small
I'm currently attempting to use PHP to transfer small files between our server and
I have a php-script that uploads files to an ftp server from a location
i am currently working at a program that transfer files via FTP. I send
I currently ftp all my files to my website when i do an update
currently I'm working on this ftp transfer. http://msdn.microsoft.com/en-us/library/ms229715.aspx I have setup my server computers
I'm currently writing a simple FTP client (using C# and .NET). It's important that
I'm currently trying to debug a customer's issue with an FTP upload feature in
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently I am using system(echo $panel_login $panel_password $root_name $root_pass $port $panel_type >> /home/shared/ftp); What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.