120, 'm' => 240, 'l' => '320'); if (!array_key_exists($thumb, $size)) { unset($thumb); } $sql = "SELECT doctype, docsize, mimetype, hash, extension, filename, pages FROM document WHERE docid=?"; $sth = $pdo->prepare($sql); $sth->execute([$docid]); $doc = $sth->fetch(PDO::FETCH_OBJ); // alter Dateiname // $ofn = sprintf("%s-%s.%s", $dtmap[$row['doctype']], $row['hash'], $row['extension']) // $file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $g_doc_typemap[$row['doctype']], $row['hash'], $row['extension']); /*if (file_exists($file)) { // Hash-Dateinamen: Umbenennen in neues Format // document-format: ttt-nnnnnn.eee // thumbnail-format: ttt-nnnnnn-ppp-s.eee $fnew = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$row['doctype']], $docid, $row['extension']); rename($file, $fnew); $file = $fnew; } else { */ $file = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$doc->doctype], $docid, $doc->extension); // } if (isset($thumb)) { if ($page < 1) { $page = 1; } elseif ($page > $doc->pages) { $page = $doc->pages; } if ($doc->mimetype == 'application/pdf') { // PDF creates PNG-thumbnails $thumbname = sprintf('%s-%06d-%03d-%s.png', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb); $thumbpath = $g_doc_basepath . '/thumb/' . $thumbname; if (!file_exists($thumbpath)) { exec("/usr/bin/mutool draw -o {$thumbpath} -w {$size[$thumb]} $file $page", $output, $retval); } } else { $thumbname = sprintf('%s-%06d-%03d-%s.%s', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb, $doc->extension); $thumbpath = $g_doc_basepath . '/thumb/' . $thumbname; if (!file_exists($thumbpath)) { list($width, $height) = getimagesize($file); $factor = $size[$thumb] / max($width, $height); // scale down if ($doc->mimetype == 'image/jpeg') { $orig = imagecreatefromjpeg($file); $scaled = imagescale($orig, $width * $factor, $height * $factor, IMG_BICUBIC); imagejpeg($scaled, $thumbpath, 85); $file = $thumbpath; $filename = $thumbname; $fsize = 0; // let's calc later } elseif ($doc->mimetype == 'image/png') { $orig = imagecreatefrompng($file); } elseif ($doc_>mimetype == 'image/xml+svg') { // TODO anything here? } } } $file = $thumbpath; $filename = $thumbname; $fsize = 0; // let's calc later } else { // normal $filename = $doc->filename; $fsize = $doc->docsize; } if (file_exists($file)) { // send file to caller header('Content-Description: File Transfer'); header('Content-Type: ' . $doc->mimetype); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); if ($fsize == 0) { header('Content-Length: ' . filesize($file)); } else { header('Content-Length: ' . $fsize); } readfile($file); exit; } else { // dynamically create error image header("Content-Type: image/png"); $im = @imagecreate(110, 20) or die(_("Cannot initialize new GD image stream")); $bgcolor = imagecolorallocate($im, 0, 0, 0); $txcolor = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "Resource not found!", $txcolor); imagepng($im); imagedestroy($im); }