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 8439795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:06:04+00:00 2026-06-10T08:06:04+00:00

Basically I’m trying to compress a directory from a relative path using the Joomla

  • 0

Basically I’m trying to compress a directory from a relative path using the Joomla JArchive::create() function. So far I can zip a directory but it zips the entire absolute path.

The code I am using that zip the absolute path is as shown below:

$zipFilesArray = array();
    $new_component_path = JPATH_SITE.'/'.'modules'.'/'.'mod_module_gen'.'/'.'package'.'/'.$new_folder_name;
    $dirs = JFolder::folders($new_component_path, '.', true, true);
    array_push($dirs, $new_component_path);
    foreach ($dirs as $dir) {
        $files = JFolder::files($dir, '.', false, true);
        foreach ($files as $file) {
            $data = JFile::read($file);
            $zipFilesArray[] = array('name' => str_replace($new_component_path.DS, '', $file), 'data' => $data);
        }
    }
    $zip = JArchive::getAdapter('zip');
    $zip->create($new_component_path.'/'.$new_folder_name.'.zip', $zipFilesArray);

I think is has something to do with using the JPATH_SITE structure which I have tried changing to the JURI::root structure but then provides an error saying that its not a valid path.

I anyone could tell me how to zip relative path in Joomla based on the code I have provided then this would be much appreciated.

  • 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-06-10T08:06:06+00:00Added an answer on June 10, 2026 at 8:06 am

    Finally have the code which was kindly given to me by another extension developer.

    $folder_path = JPATH_SITE.'/modules/mod_xxxxxxxxx/package/'.$new_folder_name;
    $new_folder_name_final = $folder_path . '.zip';
    
    $zip = new ZipArchive();
    
    if ($zip->open($new_folder_name_final, ZIPARCHIVE::CREATE) !== TRUE) {
        return false;
    }
    
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder_path));
    
    foreach ($iterator as $key=>$value) {
        $key = str_replace('\\', '/', $key);
        if (!is_dir($key)) {
            if(!$zip->addFile(realpath($key), substr($key, strlen($folder_path) - strlen(basename($folder_path))))) {
                return false;
            }
        }
    $zip->close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, what I'm trying to create is a page of div tags, each has
Basically I am trying to restart a service from a php web page. Here
Basically I want to convert a virtual path to an absolute path.
Basically from a database I am getting data that is formatted like this nameofproject101
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically this function is meant to store the height value of the element that
basically I have a function that resizes elements accordingly with jquery triggering the function
Basically, what signal does '0' represent, because here I see SIGNAL numbers starting from

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.