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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:39:03+00:00 2026-06-13T01:39:03+00:00

I made a drupal module, one of function of the module is to compress

  • 0

I made a drupal module, one of function of the module is to compress some files to be a zip package. It works fine in my local environment(xampp), but fails on server. My server does has php zip extension enabled, since I can see zip information on php info and I can unzip file with php as well.

Besides, I already chmod files to be 0777 .

My code:

$folder = file_directory_path();

$zip = new ZipArchive();

if ($zip->open('b.zip', ZIPARCHIVE::CREATE) === TRUE) {

    foreach ( $files as $file ) {
        drupal_set_message(t($file)); // I can see the the message on this stpe
        $zip->addFile($file);
    }

    $zip->close();
    if (file_exists('b.zip')) {

        copy('b.zip', $folder . '/b.zip');
        unlink('b.zip');
        global $base_url;
        variable_set('zippath', $base_url . $folder . '/b.zip');
        drupal_set_message(t('new zip package has been created'));
    }
} else {
    drupal_set_message(t('new zip package failed'));
}
  • 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-13T01:39:04+00:00Added an answer on June 13, 2026 at 1:39 am

    Yes .. i know what you mean .. this are the 3 possibility

    • You have write permissions
    • You Did not use full path
    • You are including folders as file

    You can try this

    error_reporting(E_ALL);
    ini_set("display_errors", "On");
    
    
    $fullPath = __DIR__ ; // <-------- Full Path to directory
    $fileZip = __DIR__ . "/b.zip";  // <---  Full path to zip
    
    if(!is_writable($fullPath))
    {
        trigger_error("You can't Write here");
    }
    
    $files = scandir($fullPath); // <--- Just to emulate your files
    touch($fileZip); // <----------------- Try Creating the file temopary 
    
    
    $zip = new ZipArchive();
    if ($zip->open($fileZip, ZIPARCHIVE::CREATE) === TRUE) {
    
        foreach ( $files as $file ) {
            if ($file == "." || $file == "..")
                continue;
            $fileFull = $fullPath . "/$file";
            if (is_file($fileFull)) { // <-------------- Make Sure its a file
                $zip->addFile($fileFull, $file);
            }
    
            // Play your ball
        }
        $zip->close();
    } else {
        echo "Failed";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a custom module and it works fine till I start working
Made a custom obj called Item with some string fields and one float. .h
I made a Web service in which I have a function to count some
On my Drupal site, I have made a Users page using the Views module,
I made a private section on a drupal site by writing a module that
I have created a module that works on a vanilla installation of Drupal but
Made this nice little loop for hiding and showing div's, works as a charm
Every time I make significant changes to a Drupal module (i.e. new items in
Using Drupal on a project which I made custom node types in using the
I am learning drupal and am trying to add some extra features to a

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.