- use finfo instead of looking at file extension

- translated some old german comments
This commit is contained in:
steinm 2012-10-05 19:53:13 +00:00
parent b8daa34d73
commit 3d2a4783d9

View File

@ -2,6 +2,7 @@
// MyDMS. Document Management System // MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal // Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe // Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2009-2012 Uwe Steinmann
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -90,25 +91,25 @@ if ($user->getComment() != $comment)
if (isset($_FILES["userfile"]) && is_uploaded_file($_FILES["userfile"]["tmp_name"]) && $_FILES["userfile"]["size"] > 0 && $_FILES['userfile']['error']==0) if (isset($_FILES["userfile"]) && is_uploaded_file($_FILES["userfile"]["tmp_name"]) && $_FILES["userfile"]["size"] > 0 && $_FILES['userfile']['error']==0)
{ {
$lastDotIndex = strrpos(basename($_FILES["userfile"]["name"]), "."); $finfo = new finfo(FILEINFO_MIME);
$fileType = substr($_FILES["userfile"]["name"], $lastDotIndex); echo $finfo->file($_FILES["userfile"]["tmp_name"]);
if ($fileType != ".jpg" && $filetype != ".jpeg") { if(substr($finfo->file($_FILES["userfile"]["tmp_name"]), 0, 10) != "image/jpeg") {;
UI::exitError(getMLText("user_info"),getMLText("only_jpg_user_images")); UI::exitError(getMLText("user_info"),getMLText("only_jpg_user_images"));
} }
//verkleinern des Bildes, so dass es 150 Pixel hoch ist // shrink the image to a max height of 150 px
// Originalbild einlesen // read original image
$origImg = imagecreatefromjpeg($_FILES["userfile"]["tmp_name"]); $origImg = imagecreatefromjpeg($_FILES["userfile"]["tmp_name"]);
$width = imagesx($origImg); $width = imagesx($origImg);
$height = imagesy($origImg); $height = imagesy($origImg);
// Thumbnail im Speicher erzeugen // create thumbnail in memory
$newHeight = 150; $newHeight = 150;
$newWidth = ($width/$height) * $newHeight; $newWidth = ($width/$height) * $newHeight;
$newImg = imagecreatetruecolor($newWidth, $newHeight); $newImg = imagecreatetruecolor($newWidth, $newHeight);
// Verkleinern // shrink image
imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// In File speichern // save image to file
imagejpeg($newImg, $_FILES["userfile"]["tmp_name"]); imagejpeg($newImg, $_FILES["userfile"]["tmp_name"]);
// Aufräumen // clean up
imagedestroy($origImg); imagedestroy($origImg);
imagedestroy($newImg); imagedestroy($newImg);
$user->setImage($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["type"]); $user->setImage($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["type"]);