Пример #1
0
function extract_file(&$params)
{
    if ($params['zipfile']) {
        $file_handle = popen(unzip_command($params), 'r');
        $text = '';
        while ($file_handle && !feof($file_handle)) {
            $text .= fread($file_handle, 8 * 1024);
        }
        $exit_status = pclose($file_handle);
        if ($exit_status == 0) {
            $params['content'] = $text;
            return true;
        } else {
            $params['content'] = null;
            if (strstr($_SERVER['HTTP_HOST'], 'beta')) {
                unzip_error($params, $exit_status);
            }
            return false;
        }
    } else {
        $params['content'] = file_get_contents($params['file']);
        return true;
    }
}
Пример #2
0
function extract_file($params, &$content)
{
    if ($params['zipfile']) {
        $file_handle = popen(unzip_command($params), 'r');
        $text = '';
        while ($file_handle && !feof($file_handle)) {
            $text .= fread($file_handle, 8 * 1024);
        }
        $exit_status = pclose($file_handle);
        if ($exit_status == 0) {
            $content = $text;
            return true;
        } else {
            $content = null;
            if (strstr($_SERVER['HTTP_HOST'], 'beta')) {
                // TODO: Consider using the error code from unzip_error here.
                $content = unzip_error($params, $exit_status);
                $content = $content[1];
            }
            return false;
        }
    } else {
        $content = file_get_contents($params['file']);
        return true;
    }
}