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

  • Home
  • SEARCH
  • 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 7021897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:30:36+00:00 2026-05-27T23:30:36+00:00

I’m making a website, using codeigniter, that will enable users to download files a

  • 0

I’m making a website, using codeigniter, that will enable users to download files a bit like gmail. By that I mean that the user can download only 1 file or all files in a zip folder.

Because there will be many files, I have encoded their names to avoid duplicates and stored their original names in a database which returns me an array like this:

Array
(
    [0] => Array
        (
            [file_id] => 2
            [file_name] => v6_copy.pdf
            [file_path] => uploads/4/d5/67697ff58d09d3fb25d563bf85d3f1ac.pdf
        )

    [1] => Array
        (
            [file_id] => 3
            [file_name] => v4_copy.pdf
            [file_path] => uploads/7/cf/38212079635e93a8f8f4d4a3fc2a11ff.pdf
        )

)

What I need to do is, get each file, rename them to their original names and then zip it in one zip. I’m currently trying to use the codeigniter zip helper, but I can’t seem to be able to rename the files.

foreach ($query->result() as $row) // This returns what you see above
{
    // I need to rename the file somewhere here
    $this->zip->read_file($row->filename); 
}

$this->zip->download('files_backup.zip');

Is there a way to do this without creating manually a directory, copying the files, renaming them and then zipping the file?

Any help most 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-05-27T23:30:36+00:00Added an answer on May 27, 2026 at 11:30 pm

    Thanks to @Gordon ‘s answer, I found a solution.
    He is completely right about Codeigniter not being able to rename a file, but I found a really quick change to the library and it seems to be working.

    If you go to your system>librairies->Zip.php like mentioned by @Gordon, search for “read_file” and you’ll find the function.

    Then I simply added a argument to the function and modified some of the code thereafter, see below:

    function read_file($path, $preserve_filepath = FALSE, $name = NULL) // Added $name
    {
        if ( ! file_exists($path))
        {
            return FALSE;
        }
    
        if (FALSE !== ($data = file_get_contents($path)))
        {
                if($name == NULL){  // Added a verification to see if it is set, if not set, then it does it's normal thing, if it is set, it uses the defined var.
            $name = str_replace("\\", "/", $path);
    
            if ($preserve_filepath === FALSE)
            {
                $name = preg_replace("|.*/(.+)|", "\\1", $name);
            }
                }
    
            $this->add_data($name, $data);
            return TRUE;
        }
        return FALSE;
    }
    

    I hope this helps others. Thanks again @Gordon

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.