Ejemplo n.º 1
0
$xtpl->assign('SYS_MAX_SIZE', nv_convertfromBytes($sys_max_size));
$xtpl->assign('NV_AUTO_RESIZE', $global_config['nv_auto_resize'] ? ' checked="checked"' : '');
$xtpl->assign('UPLOAD_ALT_REQUIRE', $global_config['upload_alt_require'] ? ' checked="checked"' : '');
$xtpl->assign('UPLOAD_AUTO_ALT', $global_config['upload_auto_alt'] ? ' checked="checked"' : '');
for ($index = 100; $index > 0; --$index) {
    $size = floor($index * $p_size);
    $xtpl->assign('SIZE', array('key' => $size, 'title' => nv_convertfromBytes($size), 'selected' => $size == $global_config['nv_max_size'] ? ' selected="selected"' : ''));
    $xtpl->parse('main.size');
}
$_upload_checking_mode = array('strong' => $lang_module['strong_mode'], 'mild' => $lang_module['mild_mode'], 'lite' => $lang_module['lite_mode'], 'none' => $lang_module['none_mode']);
foreach ($_upload_checking_mode as $m => $n) {
    $xtpl->assign('UPLOAD_CHECKING_MODE', array('key' => $m, 'title' => $n, 'selected' => $m == $global_config['upload_checking_mode'] ? ' selected="selected"' : ''));
    $xtpl->parse('main.upload_checking_mode');
}
$strong = false;
if (nv_function_exists('finfo_open') or nv_class_exists('finfo', false) or nv_function_exists('mime_content_type') or substr($sys_info['os'], 0, 3) != 'WIN' and (nv_function_exists('system') or nv_function_exists('exec'))) {
    $strong = true;
}
$xtpl->assign('UPLOAD_CHECKING_NOTE', !$strong ? $lang_module['upload_checking_note'] : '');
foreach ($myini['types'] as $key => $name) {
    $xtpl->assign('TYPES', array('key' => $key, 'title' => $name, 'checked' => in_array($name, $global_config['file_allowed_ext']) ? ' checked="checked"' : ''));
    $xtpl->parse('main.types');
}
foreach ($myini['exts'] as $key => $name) {
    $xtpl->assign('EXTS', array('key' => $key, 'title' => $name, 'checked' => in_array($name, $global_config['forbid_extensions']) ? ' checked="checked"' : ''));
    $xtpl->parse('main.exts');
}
foreach ($myini['mimes'] as $key => $name) {
    $xtpl->assign('MIMES', array('key' => $key, 'title' => $name, 'checked' => in_array($name, $global_config['forbid_mimes']) ? ' checked="checked"' : ''));
    $xtpl->parse('main.mimes');
}
Ejemplo n.º 2
0
/**
 * nv_get_mime_type()
 *
 * @param mixed $filename
 * @param string $magic_path
 * @param string $default_mime
 * @return
 */
function nv_get_mime_type($filename, $magic_path = '', $default_mime = 'application/octet-stream')
{
    global $sys_info;
    if (empty($filename)) {
        return false;
    }
    $_array_name = explode('.', $filename);
    $ext = strtolower(array_pop($_array_name));
    if (empty($ext)) {
        return false;
    }
    $mime = $default_mime;
    if (nv_function_exists('finfo_open')) {
        if (empty($magic_path)) {
            $finfo = finfo_open(FILEINFO_MIME);
        } elseif ($magic_path != 'auto') {
            $finfo = finfo_open(FILEINFO_MIME, $magic_path);
        } else {
            if (($magic = getenv('MAGIC')) !== false) {
                $finfo = finfo_open(FILEINFO_MIME, $magic);
            } else {
                if (substr($sys_info['os'], 0, 3) == 'WIN') {
                    $path = realpath(ini_get('extension_dir') . '/../') . 'extras/magic';
                    $finfo = finfo_open(FILEINFO_MIME, $path);
                } else {
                    $finfo = finfo_open(FILEINFO_MIME, '/usr/share/file/magic');
                }
            }
        }
        if (is_resource($finfo)) {
            $mime = finfo_file($finfo, realpath($filename));
            finfo_close($finfo);
            $mime = preg_replace('/^([\\.\\-\\w]+)\\/([\\.\\-\\w]+)(.*)$/i', '$1/$2', trim($mime));
        }
    }
    if (empty($mime) or $mime == 'application/octet-stream') {
        if (nv_class_exists('finfo', false)) {
            $finfo = new finfo(FILEINFO_MIME);
            if ($finfo) {
                $mime = $finfo->file(realpath($filename));
                $mime = preg_replace('/^([\\.-\\w]+)\\/([\\.-\\w]+)(.*)$/i', '$1/$2', trim($mime));
            }
        }
    }
    if (empty($mime) or $mime == 'application/octet-stream') {
        if (substr($sys_info['os'], 0, 3) != 'WIN') {
            if (nv_function_exists('system')) {
                ob_start();
                system('file -i -b ' . escapeshellarg($filename));
                $m = ob_get_clean();
                $m = trim($m);
                if (!empty($m)) {
                    $mime = preg_replace('/^([\\.-\\w]+)\\/([\\.-\\w]+)(.*)$/i', '$1/$2', $m);
                }
            } elseif (nv_function_exists('exec')) {
                $m = @exec('file -bi ' . escapeshellarg($filename));
                $m = trim($m);
                if (!empty($m)) {
                    $mime = preg_replace('/^([\\.-\\w]+)\\/([\\.-\\w]+)(.*)$/i', '$1/$2', $m);
                }
            }
        }
    }
    if (empty($mime) or $mime == 'application/octet-stream') {
        if (nv_function_exists('mime_content_type')) {
            $mime = mime_content_type($filename);
            $mime = preg_replace('/^([\\.-\\w]+)\\/([\\.-\\w]+)(.*)$/i', '$1/$2', trim($mime));
        }
    }
    if (empty($mime) or $mime == 'application/octet-stream') {
        $img_exts = array('png', 'gif', 'jpg', 'bmp', 'tiff', 'swf', 'psd');
        if (in_array($ext, $img_exts)) {
            if (($img_info = @getimagesize($filename)) !== false) {
                if (isset($img_info['mime']) and !empty($img_info['mime'])) {
                    $mime = trim($img_info['mime']);
                    $mime = preg_replace('/^([\\.-\\w]+)\\/([\\.-\\w]+)(.*)$/i', '$1/$2', $mime);
                }
                if (empty($mime) and isset($img_info[2])) {
                    $mime = image_type_to_mime_type($img_info[2]);
                }
            }
        }
    }
    if (empty($mime) or $mime == 'application/octet-stream') {
        $mime_types = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/mime.ini');
        if (array_key_exists($ext, $mime_types)) {
            if (is_string($mime_types[$ext])) {
                return $mime_types[$ext];
            }
            return $mime_types[$ext][0];
        }
    }
    if (preg_match('/^application\\/(?:x-)?zip(?:-compressed)?$/is', $mime)) {
        if ($ext == 'docx') {
            $mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
        } elseif ($ext == 'dotx') {
            $mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
        } elseif ($ext == 'potx') {
            $mime = 'application/vnd.openxmlformats-officedocument.presentationml.template';
        } elseif ($ext == 'ppsx') {
            $mime = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
        } elseif ($ext == 'pptx') {
            $mime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
        } elseif ($ext == 'xlsx') {
            $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        } elseif ($ext == 'xltx') {
            $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
        } elseif ($ext == 'docm') {
            $mime = 'application/vnd.ms-word.document.macroEnabled.12';
        } elseif ($ext == 'dotm') {
            $mime = 'application/vnd.ms-word.template.macroEnabled.12';
        } elseif ($ext == 'potm') {
            $mime = 'application/vnd.ms-powerpoint.template.macroEnabled.12';
        } elseif ($ext == 'ppam') {
            $mime = 'application/vnd.ms-powerpoint.addin.macroEnabled.12';
        } elseif ($ext == 'ppsm') {
            $mime = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12';
        } elseif ($ext == 'pptm') {
            $mime = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12';
        } elseif ($ext == 'xlam') {
            $mime = 'application/vnd.ms-excel.addin.macroEnabled.12';
        } elseif ($ext == 'xlsb') {
            $mime = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12';
        } elseif ($ext == 'xlsm') {
            $mime = 'application/vnd.ms-excel.sheet.macroEnabled.12';
        } elseif ($ext == 'xltm') {
            $mime = 'application/vnd.ms-excel.template.macroEnabled.12';
        }
    }
    return $mime;
}