Welcome Guest, Not a member yet? Register   Sign In
Unload to Use Zip Library
#1

[eluser]squarebones[/eluser]
This is an interesting problem. I wanted to do a simple zip download of my web directory from a shared hosting situation. Unfortunately, I got a weird error. So I tried reducing the download to one single file.

The config is such:

Code:
$config['backup_file'] = "/path/from/web/host/to/application/views/footer.php";

The following is the controller I created to read the file and affect the download:

Code:
class Backup_site extends Controller {
    function Backup_site()
    {
        parent::Controller();
        $this->load->library('zip');
    }

    function backup_itup()
    {
        $path = $this->config->item('backup_file');
        $this->zip->read_file($path);
        $this->zip->download('one_file.zip');
    }
}

I confirmed that the zlib library is being loaded by my web host (compiled --with bzip2 and loading Zlib v1.2.3) and all seems well. By commenting out the $this->zip->download line, I at least get a blank page meaning that (with error reporting set at 4) the read_file is being performed, but if the script hits $this->zip->download('one_file.zip'); I get this error on my screen:

A PHP Error was encountered

Severity: Notice

Message: Only variables should be assigned by reference

Filename: libraries/Zip.php

Line Number: 328

That line of code is in the Zip library in this function:

Code:
/**
     * Download
     *
     * @access    public
     * @param    string    the file name
     * @param    string    the data to be encoded
     * @return    bool
     */
    function download($filename = 'backup.zip')
    {
        if ( ! preg_match("|.+?\.zip$|", $filename))
        {
            $filename .= '.zip';
        }

        $zip_content =& $this->get_zip(); // This is the errant line that is throwing the error

        $CI =& get_instance();
        $CI->load->helper('download');

        force_download($filename, $zip_content);
    }
So, at this point, I have to give up on this library being at all useful in my situation. I can't even get it to download an empty zip archive (reported by another user as a bug), which would be something at least.

I don't know what this requires to function properly as the user guide lists no requirements for correct operation.

Should this be reported as a bug?
#2

[eluser]pistolPete[/eluser]
This seems to be a PHP4 bug, are you using PHP 4.4.x ?
I just tried it on PHP 5.2.6, it's working fine.

Please try the following (just for testing):

Solution 1:
Change line 266 in ./system/libraries/Zip.php from
Code:
function get_zip()
to
Code:
function & get_zip()

Solution 2:
Change line 328 in ./system/libraries/Zip.php from
Code:
$zip_content =& $this->get_zip();
to
Code:
$zip_content = $this->get_zip();
#3

[eluser]squarebones[/eluser]
That's what I was just thinking! My web host gives me the choice between PHP4 and PHP5. I am going to now switch it to PHP5 as the preferential choice and try my script again.

Thanks for the (near) confirmation. And I'll keep this thread posted.
#4

[eluser]squarebones[/eluser]
Yikes! Isn't CI supposed to be PHP4 friendly? Sounds like that library is broken for those of us (who used to be) still under the dictates of PHP4.

Maybe the CI team needs to take a look at that library a little closer (or just switch the whole shooting match to PHP5).
#5

[eluser]Derek Allard[/eluser]
Hey squarebones, welcome to CodeIgniter!

I can't tell from this thread, were either of the solutions proposed implemented by you or tested, and if so, in what PHP versions? Did they work, what do you think of them?

Has anyone else tested?

Yes, CodeIgniter is PHP4 friendly, one single missing ampersand shouldn't lead you to think otherwise, you have hundreds of thousands of lines of code that are evidence of our commitment to PHP4 after all. Perhaps you could help us look at that library a little closer.
#6

[eluser]squarebones[/eluser]
Yes, the first solution worked. At least on MAMP... I haven't been having much luck getting my site working on my shared hosting server, as yet, but as soon as I am able to and test it out, I'll let you know.

Anyway, it's a useful solution and easy to implement.
#7

[eluser]squarebones[/eluser]
Should have read the rest of your post before replying so quickly and incompletely. I tried switching my PHP version on my web host to PHP5 and running the site that worked so well under PHP4, and it was a disaster! Nothing seemed to work right. So I switched the pref back to PHP4 and all was wonderful again. You are right about it being PHP4 friendly, and I put foot in mouth about saying it wasn't. It's such a Godsend to development, that I can't laud it enough. It has saved me SO many hours of procedural development and reduced the number of lines of code I had to slog through, not so long ago, just to get some simple procedure to work correctly (not to mention the gallons of sweat and blood I lost). I was one of those programmers who loved to pack thousands of lines of code into one big ol' script and tried to make it work with ifs, elseifs, switches, and who knows what else. Those days are long over now that I have CI in my work belt.

Thank you to all the CI developers out there. Keep up the good work.
#8

[eluser]pistolPete[/eluser]
I tried it aswell, using PHP 4.4.8.

It is working using my first solution:

Code:
function & get_zip()
#9

[eluser]Geoffrey[/eluser]
I created a MY_Zip.php library with the change below to the relevant function rather than edit a system library but with the advertised PHP4 support of CodeIgniter shouldn't this be logged as a bug?

[quote author="pistolPete" date="1234825814"]
Change line 328 in ./system/libraries/Zip.php from
Code:
$zip_content =& $this->get_zip();
to
Code:
$zip_content = $this->get_zip();
[/quote]

PHP Version: 4.4.9




Theme © iAndrew 2016 - Forum software by © MyBB