Welcome Guest, Not a member yet? Register   Sign In
Missing files when using Zip Encoding Library
#3

[eluser]captainredmuff[/eluser]
The following code snippet taken from Possible Bug in Zip Library (posted almost a year ago) seems to be a temporary fix to this issue.

Code:
//overload the read_dir function to fix issues with blank zip files
    function read_dir($path, $preserve_filepath = FALSE)
    {
        if ($fp = @opendir($path))
        {
            while (FALSE !== ($file = readdir($fp)))
            {
                if (@is_dir($path.$file) && substr($file, 0, 1) != '.')
                {
                    $this->read_dir($path.$file."/");
                }
                elseif (substr($file, 0, 1) != ".")
                {
                    $this->read_file(str_replace("\\", "/", $path).$file, $preserve_filepath);
                }
            }
            return TRUE;
        }
        return FALSE;
    }

As mentioned previously, this snippet does indeed zip the requested files but neglects to maintain the appropriate directory structure.

To circumvent this, the $preserve_filepath flag should be set to true, however, this simply reverts back to missing files in the resulting zip file rendering this fix useless.

Following the flow of the function brings us to the following method in the Zip Library.

Code:
function read_file($path, $preserve_filepath = FALSE)
    {
        if ( ! file_exists($path))
        {
            return FALSE;
        }

        if (FALSE !== ($data = file_get_contents($path)))
        {
            $name = str_replace("\\", "/", $path);
            
            if ($preserve_filepath === FALSE)
            {
                $name = preg_replace("|.*/(.+)|", "\\1", $name);
            }

            $this->add_data($name, $data);
            return TRUE;
        }
        return FALSE;
    }

As can be seen from the $preserve_filepath flag, the $name (path to the current file) variable is being cleansed via some regex trickery (which i'm assuming trims the file name from the file path). As the $preserve_filepath flag seems to be the only stumbling block i have managed to narrow this bug down to so far, i'm not entirely sure where to begin looking next?

One thing i have noticed from browsing the source of the Zip Library is that no implicit calls are made to $this->add_dir();. I don't know if this is an issue, but it seems to me that subdirectories would fail to be created when recursing using read_dir() which may be the cause of the problem. Once again, i'm unsure if this is an issue or not.


Messages In This Thread
Missing files when using Zip Encoding Library - by El Forum - 01-08-2009, 06:49 AM
Missing files when using Zip Encoding Library - by El Forum - 01-09-2009, 03:48 AM
Missing files when using Zip Encoding Library - by El Forum - 01-12-2009, 04:11 AM
Missing files when using Zip Encoding Library - by El Forum - 01-15-2009, 05:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB