Exemplo n.º 1
0
 function uploadAvatar($input_name, $max_file_size)
 {
     $overwrite = 1;
     $dir = 'upload/avatars/';
     $file_types = array(1 => 'jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
     $file_mimes = array(1 => 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
     $file_name = $_SESSION['login'] . '_user';
     if (isset($_POST['send_avatar'])) {
         if (!$_FILES[$input_name]['name']) {
             $this->msg('Nie wybrano pliku do załadowania!', 1);
         } else {
             if (filesize($_FILES[$input_name]['tmp_name']) <= $max_file_size * 1024) {
                 $file_ex = pathinfo($_FILES[$input_name]['name']);
                 $image_info = @getimagesize($_FILES[$input_name]['tmp_name']);
                 if (array_search($file_ex['extension'], $file_types) && array_search($image_info['mime'], $file_mimes)) {
                     if ($overwrite == 0 && file_exists($dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Taki plik już istnieje.', 1);
                     }
                     if (!move_uploaded_file($_FILES[$input_name]['tmp_name'], $dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Wgrywanie pliku nie powiodło się.', 1);
                     } else {
                         $upload_dir = $dir . $file_name . "." . $file_ex['extension'];
                         mysql_query("UPDATE `{$this->table}` SET `avatar`='{$upload_dir}' WHERE `user`='" . $_SESSION['login'] . "'");
                         //Zmina rozmiaru avatara
                         list($width, $height, $type, $attr) = getimagesize($upload_dir);
                         if ($width > 120 || $height > 120) {
                             require_once 'admin/lib/imageworkshop.lib.php';
                             $createFolders = false;
                             $backgroundColor = null;
                             $imageQuality = 95;
                             $imageLayer = new ImageWorkshop(array("imageFromPath" => $upload_dir));
                             $imageLayer->resizeInPixel(120, 120, true);
                             $imageLayer->save($dir, $file_name . "." . $file_ex['extension'], $createFolders, $backgroundColor, $imageQuality);
                         }
                         $this->msg('Avatar został pomyślnie załadowany.', 3);
                     }
                 } else {
                     $this->msg('Niedozwolone rozszerzenie lub typ pliku!', 1);
                 }
             } else {
                 $this->msg('Wybrany plik jest za wielki! Dozwolony rozmiar to ' . $max_file_size . ' kB.', 1);
             }
         }
     }
 }
Exemplo n.º 2
0
 function watermark($file, $watermark, $dir)
 {
     require_once 'admin/lib/imageworkshop.lib.php';
     $info = pathinfo($file);
     if ($info['extension'] != 'gif') {
         $imageLayer = new ImageWorkshop(array("imageFromPath" => $file));
         $watermarkLayer = new ImageWorkshop(array("imageFromPath" => $watermark));
         $imageLayer->addLayer(1, $watermarkLayer, 5, 5, "RB");
         $createFolders = false;
         $backgroundColor = null;
         $imageQuality = 100;
         $imageLayer->save($dir, $info['filename'] . '.' . $info['extension'], $createFolders, $backgroundColor, $imageQuality);
     }
 }