elFinder::zipdl PHP Метод

zipdl() защищенный Метод

1st: Return srrsy contains download archive file info 2nd: Return array contains opened file pointer, root itself and required headers
Автор: Naoki Sawada
protected zipdl ( $args ) : array
Результат array
    protected function zipdl($args)
    {
        $targets = $args['targets'];
        $download = !empty($args['download']);
        $h404 = 'HTTP/1.x 404 Not Found';
        if (!$download) {
            //1st: Return srrsy contains download archive file info
            $error = array(self::ERROR_ARCHIVE);
            if (($volume = $this->volume($targets[0])) !== false) {
                if ($dlres = $volume->zipdl($targets)) {
                    $path = $dlres['path'];
                    register_shutdown_function(create_function('$f', 'connection_status() && is_file($f) && unlink($f);'), $path);
                    if (count($targets) === 1) {
                        $name = basename($volume->path($targets[0]));
                    } else {
                        $name = $dlres['prefix'] . '_Files';
                    }
                    $name .= '.' . $dlres['ext'];
                    $result = array('zipdl' => array('file' => basename($path), 'name' => $name, 'mime' => $dlres['mime']));
                    return $result;
                }
                $error = array_merge($error, $volume->error());
            }
            return array('error' => $error);
        } else {
            // 2nd: Return array contains opened file pointer, root itself and required headers
            if (count($targets) !== 4 || ($volume = $this->volume($targets[0])) == false) {
                return array('error' => 'File not found', 'header' => $h404, 'raw' => true);
            }
            $file = $targets[1];
            $path = $volume->getTempPath() . DIRECTORY_SEPARATOR . $file;
            register_shutdown_function(create_function('$f', 'is_file($f) && unlink($f);'), $path);
            if (!is_readable($path)) {
                return array('error' => 'File not found', 'header' => $h404, 'raw' => true);
            }
            $name = $targets[2];
            $mime = $targets[3];
            $filenameEncoded = rawurlencode($name);
            if (strpos($filenameEncoded, '%') === false) {
                // ASCII only
                $filename = 'filename="' . $name . '"';
            } else {
                $ua = $_SERVER['HTTP_USER_AGENT'];
                if (preg_match('/MSIE [4-8]/', $ua)) {
                    // IE < 9 do not support RFC 6266 (RFC 2231/RFC 5987)
                    $filename = 'filename="' . $filenameEncoded . '"';
                } elseif (strpos($ua, 'Chrome') === false && strpos($ua, 'Safari') !== false && preg_match('#Version/[3-5]#', $ua)) {
                    // Safari < 6
                    $filename = 'filename="' . str_replace('"', '', $name) . '"';
                } else {
                    // RFC 6266 (RFC 2231/RFC 5987)
                    $filename = 'filename*=UTF-8\'\'' . $filenameEncoded;
                }
            }
            $fp = fopen($path, 'rb');
            $file = fstat($fp);
            $result = array('pointer' => $fp, 'header' => array('Content-Type: ' . $mime, 'Content-Disposition: attachment; ' . $filename, 'Content-Transfer-Encoding: binary', 'Content-Length: ' . $file['size'], 'Accept-Ranges: none', 'Connection: close'));
            return $result;
        }
    }