Exemplo n.º 1
0
/**
 * Upload a file
 *
 */
function uploadfile()
{
    global $Cfg, $Paths, $Users, $Pivot_Vars, $qual, $local;
    MinLevel(2);
    include_once 'includes/fileupload-class.php';
    $lang = str_replace("_utf8", "", $Users[$Pivot_Vars['user']]['language']);
    $my_uploader = new uploader($lang);
    // OPTIONAL: set the max filesize of uploadable files in bytes
    $my_uploader->max_filesize($Cfg['max_filesize']);
    // UPLOAD the file
    if ($my_uploader->upload('userfile', $Cfg['upload_accept'], $Cfg['upload_extension'])) {
        debug($my_uploader->file['name']);
        $success = $my_uploader->save_file($Paths['upload_path'], $Cfg['upload_save_mode'], 1);
    }
    if ($success) {
        error_reporting(E_ALL);
        include_once "modules/module_imagefunctions.php";
        PageHeader(lang('userbar', 'main'), 1);
        PageAnkeiler(lang('userbar', 'files') . ' » ' . lang('userbar', 'uploaded_success'));
        printf('<script type="text/javascript">function pop(a){
			window.open("modules/module_image.php?image="+a,"",
				"toolbar=no,resizable=yes,scrollbars=yes,width=940,height=570");
			self.location="index.php?menu=files";}
                        </script>');
        echo '<tr><td align="center" colspan="2">';
        $fullentry = $Paths['upload_url'] . $my_uploader->file['name'];
        echo '<img src="' . $fullentry . '" border="0" alt="new image">';
        echo '</td></tr><tr><td align="right" width="48%"><br /><br />';
        if (auto_thumbnail($my_uploader->file['name'])) {
            echo "<p><b>Thumbnail:</b><br>";
            $thumbfilename = $Paths['upload_url'] . make_thumbname(basename($my_uploader->file['name']));
            printf('<p><img src="%s" />', $thumbfilename);
            printf('<p><a href="javascript:pop(\'%s\')">' . lang('upload', 'edit_thumbnail') . '</a></td>', $my_uploader->file['name']);
        } else {
            printf('<p><a href="javascript:pop(\'%s\');">' . lang('upload', 'create_thumb') . '</a></td>', $my_uploader->file['name']);
        }
        GenSetting('', lang('upload', 'thisfile'), '', 8, '', 6);
        StartForm('file_upload', 0, 'enctype="multipart/form-data"');
        printf('<input name="%s" type="file"  class="input"><br />', $Cfg['upload_file_name']);
        printf('<input type="submit" value="%s" class="button" /></form>', lang('upload', 'button'));
        PageFooter();
    } else {
        if ($my_uploader->errors) {
            files_main($my_uploader->errors);
        }
    }
}
/**
 * Creates a thumbnail using the GD library.
 *
 * Currently only JPEG and PNG is supported (in the GD library).
 *
 * @param string $imagename
 * @return boolean
 */
function auto_thumbnail($imagename)
{
    global $Paths, $Cfg, $qual, $local;
    // if $local is false, we don't automatically make a thumbnail..
    if ($local == FALSE) {
        return FALSE;
    }
    $ext = getextension($imagename);
    if ($ext == "jpeg") {
        $ext = "jpg";
    }
    $thumbname = make_thumbname(basename($imagename));
    $filename = $Paths['upload_path'] . $imagename;
    $thumbfilename = $Paths['upload_path'] . $thumbname;
    $width = $Cfg['upload_thumb_width'];
    $height = $Cfg['upload_thumb_height'];
    // We are current only handling JPEG and PNG.
    if ($ext == "jpg") {
        $src = ImageCreateFromJPEG($filename);
    } elseif ($ext == "png") {
        $src = ImageCreateFromPNG($filename);
    } else {
        debug("Can not auto create thumb for " . basename($filename) . " - unsupported extension.");
        return FALSE;
    }
    list($curwidth, $curheight) = getimagesize($filename);
    $scale = min($curheight / $height, $curwidth / $width);
    if (function_exists('ImageCreateTrueColor')) {
        $dst = ImageCreateTrueColor($width, $height);
    } else {
        $dst = ImageCreate($width, $height);
    }
    $startx = $width / 2 - $curwidth / 2 / $scale;
    $endx = $width / 2 + $curwidth / 2 / $scale - $startx;
    $starty = $height / 2 - $curheight / 2 / $scale;
    $endy = $height / 2 + $curheight / 2 / $scale - $starty;
    //echo "Start en stop: $starty tot $endy<br />";
    ImageCopyResampled($dst, $src, $startx, $starty, 0, 0, $endx, $endy, $curwidth, $curheight);
    if ($ext == "jpg") {
        ImageJPEG($dst, $thumbfilename, $qual);
    }
    if ($ext == "png") {
        ImagePNG($dst, $thumbfilename, $qual);
    }
    ImageDestroy($src);
    ImageDestroy($dst);
    return TRUE;
}